]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
remove Error out parameters, use exceptions
authorJuerg Billeter <j@bitron.ch>
Thu, 12 Jul 2007 12:36:46 +0000 (12:36 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 12 Jul 2007 12:36:46 +0000 (12:36 +0000)
2007-07-12  Juerg Billeter  <j@bitron.ch>

* ccode/valaccodewriter.vala, gobject/valaccodecompiler.vala,
  compiler/valacompiler.vala, vapi/glib-2.0.vala,
  gobject-introspection/gidl.vala, vapigen/valagidlparser.vala,
  vapigen/valavapigen.vala: remove Error out parameters, use exceptions

svn path=/trunk/; revision=352

ChangeLog
ccode/valaccodewriter.vala
compiler/valacompiler.vala
gobject-introspection/gidl.vala
gobject/valaccodecompiler.vala
vapi/glib-2.0.vala
vapigen/valagidlparser.vala
vapigen/valavapigen.vala

index 1b446004e4dbee4f83103d3bd390a53217d325b3..ba9ba538af30bc29afea2da3c3a22bf1ae51b72a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-07-12  Jürg Billeter  <j@bitron.ch>
+
+       * ccode/valaccodewriter.vala, gobject/valaccodecompiler.vala,
+         compiler/valacompiler.vala, vapi/glib-2.0.vala,
+         gobject-introspection/gidl.vala, vapigen/valagidlparser.vala,
+         vapigen/valavapigen.vala: remove Error out parameters, use exceptions
+
 2007-07-12  Jürg Billeter  <j@bitron.ch>
 
        * gobject/valacodegenerator.vala: support exception handling in
index 9972b988f4726fc862ea9ec7556028f0b1bb7ee3..3e33359c161d32f93101bac53ea7399c0a85a87c 100644 (file)
@@ -77,17 +77,21 @@ public class Vala.CCodeWriter {
                
                if (file_exists) {
                        var changed = true;
-               
-                       var old_file = new MappedFile (_filename, false, null);
-                       var new_file = new MappedFile (temp_filename, false, null);
-                       var len = old_file.get_length ();
-                       if (len == new_file.get_length ()) {
-                               if (Memory.cmp (old_file.get_contents (), new_file.get_contents (), len) == 0) {
-                                       changed = false;
+
+                       try {
+                               var old_file = new MappedFile (_filename, false);
+                               var new_file = new MappedFile (temp_filename, false);
+                               var len = old_file.get_length ();
+                               if (len == new_file.get_length ()) {
+                                       if (Memory.cmp (old_file.get_contents (), new_file.get_contents (), len) == 0) {
+                                               changed = false;
+                                       }
                                }
+                               old_file = null;
+                               new_file = null;
+                       } catch (FileError e) {
+                               // assume changed if mmap comparison doesn't work
                        }
-                       old_file = null;
-                       new_file = null;
                        
                        if (changed) {
                                FileUtils.rename (temp_filename, _filename);
index f63377d04ed42a3dee7f3700de53e93106d87e16..7ac07ff5452de78100e3b718c10856ed820e4a45 100644 (file)
@@ -122,15 +122,19 @@ class Vala.Compiler {
                
                var deps_filename = Path.build_filename (Path.get_dirname (package_path), "%s.deps".printf (pkg));
                if (FileUtils.test (deps_filename, FileTest.EXISTS)) {
-                       string deps_content;
-                       long deps_len;
-                       FileUtils.get_contents (deps_filename, out deps_content, out deps_len, null);
-                       foreach (string dep in deps_content.split ("\n")) {
-                               if (dep != "") {
-                                       if (!add_package (context, dep)) {
-                                               Report.error (null, "%s, dependency of %s, not found in specified Vala API directories".printf (dep, pkg));
+                       try {
+                               string deps_content;
+                               long deps_len;
+                               FileUtils.get_contents (deps_filename, out deps_content, out deps_len);
+                               foreach (string dep in deps_content.split ("\n")) {
+                                       if (dep != "") {
+                                               if (!add_package (context, dep)) {
+                                                       Report.error (null, "%s, dependency of %s, not found in specified Vala API directories".printf (dep, pkg));
+                                               }
                                        }
                                }
+                       } catch (FileError e) {
+                               Report.error (null, "Unable to read dependency file: %s".printf (e.message));
                        }
                }
                
@@ -255,15 +259,13 @@ class Vala.Compiler {
        }
        
        static int main (string[] args) {
-               Error err = null;
-       
-               var opt_context = new OptionContext ("- Vala Compiler");
-               opt_context.set_help_enabled (true);
-               opt_context.add_main_entries (options, null);
-               opt_context.parse (out args, out err);
-               
-               if (err != null) {
-                       stdout.printf ("%s\n", err.message);
+               try {
+                       var opt_context = new OptionContext ("- Vala Compiler");
+                       opt_context.set_help_enabled (true);
+                       opt_context.add_main_entries (options, null);
+                       opt_context.parse (out args);
+               } catch (OptionError e) {
+                       stdout.printf ("%s\n", e.message);
                        stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
                        return 1;
                }
index 1973d66ffeb30528e488c38739f4de023edd2fa0..31a809edd79b3a45a219484f0e350b46a65bb11f 100644 (file)
@@ -24,7 +24,7 @@
 namespace GLib {
        [CCode (cheader_filename = "gidlparser.h")]
        public struct Idl {
-               public static List<IdlModule> parse_file (string! filename, out Error error);
+               public static List<IdlModule> parse_file (string! filename) throws MarkupError;
        }
        
        [CCode (cheader_filename = "gidlmodule.h")]
index 9d7e2d1eddd74df91b5c1220de0ed40e020f6f62..2de7a591d76667ca0f87521414d97a304c6b7ed2 100644 (file)
@@ -49,12 +49,14 @@ public class Vala.CCodeCompiler {
                }
                string pkgflags;
                int exit_status;
-               Error err = null;
-               if (!Process.spawn_command_line_sync (pc, out pkgflags, null, ref exit_status, out err)) {
-                       Report.error (null, err.message);
-                       return;
-               } else if (exit_status != 0) {
-                       Report.error (null, "pkg-config exited with status %d".printf (exit_status));
+               try {
+                       Process.spawn_command_line_sync (pc, out pkgflags, null, out exit_status);
+                       if (exit_status != 0) {
+                               Report.error (null, "pkg-config exited with status %d".printf (exit_status));
+                               return;
+                       }
+               } catch (SpawnError e) {
+                       Report.error (null, e.message);
                        return;
                }
 
@@ -80,7 +82,14 @@ public class Vala.CCodeCompiler {
                        }
                }
 
-               bool success = Process.spawn_command_line_sync (cmdline, null, null, ref exit_status, out err);
+               try {
+                       Process.spawn_command_line_sync (cmdline, null, null, out exit_status);
+                       if (exit_status != 0) {
+                               Report.error (null, "cc exited with status %d".printf (exit_status));
+                       }
+               } catch (SpawnError e) {
+                       Report.error (null, e.message);
+               }
 
                /* remove generated C source and header files */
                foreach (SourceFile file in source_files) {
@@ -89,11 +98,5 @@ public class Vala.CCodeCompiler {
                                FileUtils.unlink (file.get_cheader_filename ());
                        }
                }
-
-               if (!success) {
-                       Report.error (null, err.message);
-               } else if (exit_status != 0) {
-                       Report.error (null, "cc exited with status %d".printf (exit_status));
-               }
        }
 }
index 0948bd8f3876ac1dd043292ffb466525f6b6108a..d13f3ef57127aa85ca3fa4c366c6b3bf9079616b 100644 (file)
@@ -792,7 +792,12 @@ namespace GLib {
        }
        
        public static delegate bool SourceFunc (pointer data);
-       
+
+       [ErrorDomain]
+       public enum ThreadError {
+               AGAIN
+       }
+
        /* Thread support */
        [ReferenceType ()]
        public struct ThreadFunctions {
@@ -812,8 +817,8 @@ namespace GLib {
        public struct Thread {
                public static void init (ThreadFunctions vtable = null);
                public static bool supported ();
-               public static weak Thread create (ThreadFunc func, pointer data, bool joinable, out Error error);
-               public static weak Thread create_full (ThreadFunc func, pointer data, ulong stack_size, bool joinable, bool bound, ThreadPriority priority, out Error error);
+               public static weak Thread create (ThreadFunc func, pointer data, bool joinable) throws ThreadError;
+               public static weak Thread create_full (ThreadFunc func, pointer data, ulong stack_size, bool joinable, bool bound, ThreadPriority priority) throws ThreadError;
                public static weak Thread self ();
                public pointer join ();
                public void set_priority (ThreadPriority priority);
@@ -846,9 +851,9 @@ namespace GLib {
        
        [ReferenceType (free_function = "g_thread_pool_free")]
        public struct ThreadPool {
-               public ThreadPool (Func func, pointer user_data, int max_threads, bool exclusive, out Error error);
-               public void push (pointer data, out Error error);
-               public void set_max_threads (int max_threads, out Error error);
+               public ThreadPool (Func func, pointer user_data, int max_threads, bool exclusive) throws ThreadError;
+               public void push (pointer data) throws ThreadError;
+               public void set_max_threads (int max_threads) throws ThreadError;
                public int get_max_threads ();
                public uint get_num_threads ();
                public uint unprocessed ();
@@ -922,17 +927,17 @@ namespace GLib {
        
        [ReferenceType (dup_function = "g_io_channel_ref", free_function = "g_io_channel_unref")]
        public struct IOChannel {
-               public IOChannel.file (string! filename, string! mode, out Error error);
-               public IOStatus read_chars (string! buf, ulong count, out ulong bytes_read, out Error error);
-               public IOStatus read_unichar (out unichar thechar, out Error error);
-               public IOStatus read_line (out string str_return, out ulong length, out ulong terminator_pos, out Error error);
-               public IOStatus read_line_string (String! buffer, out ulong terminator_pos, out Error error);
-               public IOStatus read_to_end (out string str_return, out ulong length, out Error error);
-               public IOStatus write_chars (string! buf, long count, out ulong bytes_written, out Error error);
-               public IOStatus write_unichar (unichar thechar, out Error error);
-               public IOStatus flush (out Error error);
-               public IOStatus seek_position (int64 offset, SeekType type, out Error error);
-               public IOStatus shutdown (bool flush, out Error error);
+               public IOChannel.file (string! filename, string! mode) throws FileError;
+               public IOStatus read_chars (string! buf, ulong count, out ulong bytes_read) throws ConvertError, IOChannelError;
+               public IOStatus read_unichar (out unichar thechar) throws ConvertError, IOChannelError;
+               public IOStatus read_line (out string str_return, out ulong length, out ulong terminator_pos) throws ConvertError, IOChannelError;
+               public IOStatus read_line_string (String! buffer, out ulong terminator_pos) throws ConvertError, IOChannelError;
+               public IOStatus read_to_end (out string str_return, out ulong length) throws ConvertError, IOChannelError;
+               public IOStatus write_chars (string! buf, long count, out ulong bytes_written) throws ConvertError, IOChannelError;
+               public IOStatus write_unichar (unichar thechar) throws ConvertError, IOChannelError;
+               public IOStatus flush () throws IOChannelError;
+               public IOStatus seek_position (int64 offset, SeekType type) throws IOChannelError;
+               public IOStatus shutdown (bool flush) throws IOChannelError;
        }
 
        [CCode (cprefix = "G_IO_")]
@@ -958,7 +963,20 @@ namespace GLib {
                EOF,
                AGAIN
        }
-       
+
+       [ErrorDomain]
+       public enum IOChannelError {
+               FBIG,
+               INVAL,
+               IO,
+               ISDIR,
+               NOSPC,
+               NXIO,
+               OVERFLOW,
+               PIPE,
+               FAILED
+       }
+
        /* Error Reporting */
 
        [ReferenceType (dup_function = "g_error_copy", free_function = "g_error_free")]
@@ -1015,7 +1033,7 @@ namespace GLib {
        
        /* Character Set Conversions */
        
-       public static string convert (string! str, long len, string! to_codeset, string! from_codeset, out int bytes_read, out int bytes_written, out Error error);
+       public static string convert (string! str, long len, string! to_codeset, string! from_codeset, out int bytes_read, out int bytes_written) throws ConvertError;
 
        public struct IConv {
                [CCode (cname = "g_iconv_open")]
@@ -1026,11 +1044,21 @@ namespace GLib {
        }
 
        public struct Filename {
-               public static string from_uri (string! uri, out string hostname = null, out Error error = null);
-               public static string to_uri (string! filename, string hostname = null, out Error error = null);
+               public static string from_uri (string! uri, out string hostname = null) throws ConvertError;
+               public static string to_uri (string! filename, string hostname = null) throws ConvertError;
                public static string display_basename (string! filename);
        }
-       
+
+       [ErrorDomain]
+       public enum ConvertError {
+               NO_CONVERSION,
+               ILLEGAL_SEQUENCE,
+               FAILED,
+               PARTIAL_INPUT,
+               BAD_URI,
+               NOT_ABSOLUTE_PATH
+       }
+
        /* Base64 Encoding */
        
        public struct Base64 {
@@ -1080,12 +1108,12 @@ namespace GLib {
                SEPTEMBER,
                OCTOBER,
                NOVEMBER,
-               DECEMBER
+               DECEMBER;
 
-               // [CCode (cname = "g_date_get_days_in_month")]
-               // public uchar get_days_in_month (DateYear year);
-               // [CCode (cname = "g_date_valid_month")]
-               // public bool valid (); 
+               [CCode (cname = "g_date_get_days_in_month")]
+               public uchar get_days_in_month (DateYear year);
+               [CCode (cname = "g_date_valid_month")]
+               public bool valid (); 
        }
 
        public struct DateYear : ushort {
@@ -1111,10 +1139,10 @@ namespace GLib {
                THURSDAY,
                FRIDAY,
                SATURDAY,
-               SUNDAY
+               SUNDAY;
 
-               // [CCode (cname = "g_date_valid_weekday")]
-               // public bool valid (); 
+               [CCode (cname = "g_date_valid_weekday")]
+               public bool valid (); 
        }
 
        [ReferenceType (free_function = "g_date_free")]
@@ -1233,7 +1261,8 @@ namespace GLib {
        }
        
        /* Spawning Processes */
-       
+
+       [ErrorDomain]
        public enum SpawnError {
                FORK,
                READ,
@@ -1256,7 +1285,7 @@ namespace GLib {
                LIBBAD,
                FAILED
        }
-       
+
        [CCode (cprefix = "G_SPAWN_")]
        public enum SpawnFlags {
                LEAVE_DESCRIPTOR_OPEN,
@@ -1267,24 +1296,53 @@ namespace GLib {
                CHILS_INHERITS_STDIN,
                FILE_AND_ARGV_ZERO
        }
-       
+
        public static delegate void SpawnChildSetupFunc (pointer user_data);
-       
+
        [CCode (cprefix = "g_")]
        public struct Process {
                [NoArrayLength ()]
-               public static bool spawn_async_with_pipes (string working_directory, string[] argv, string[] envp, SpawnFlags _flags, SpawnChildSetupFunc child_setup, pointer user_data, Pid child_pid, out int standard_input, out int standard_output, out int standard_error, out Error error);
+               public static bool spawn_async_with_pipes (string working_directory, string[] argv, string[] envp, SpawnFlags _flags, SpawnChildSetupFunc child_setup, pointer user_data, Pid child_pid, out int standard_input = null, out int standard_output = null, out int standard_error = null) throws SpawnError;
                [NoArrayLength ()]
-               public static bool spawn_async (string working_directory, string[] argv, string[] envp, SpawnFlags _flags, SpawnChildSetupFunc child_setup, pointer user_data, Pid child_pid, out Error error);
+               public static bool spawn_async (string working_directory, string[] argv, string[] envp, SpawnFlags _flags, SpawnChildSetupFunc child_setup, pointer user_data, Pid child_pid) throws SpawnError;
                [NoArrayLength ()]
-               public static bool spawn_sync (string working_directory, string[] argv, string[] envp, SpawnFlags _flags, SpawnChildSetupFunc child_setup, pointer user_data, out string standard_output, out string standard_error, out int exit_status, out Error error);
-               public static bool spawn_command_line_async (string! command_line, out Error error);
-               public static bool spawn_command_line_sync (string! command_line, out string standard_output, out string standard_error, out int exit_status, out Error error);
+               public static bool spawn_sync (string working_directory, string[] argv, string[] envp, SpawnFlags _flags, SpawnChildSetupFunc child_setup, pointer user_data, out string standard_output = null, out string standard_error = null, out int exit_status = null) throws SpawnError;
+               public static bool spawn_command_line_async (string! command_line) throws SpawnError;
+               public static bool spawn_command_line_sync (string! command_line, out string standard_output = null, out string standard_error = null, out int exit_status = null) throws SpawnError;
                public static void close_pid (Pid pid);
        }
        
        /* File Utilities */
 
+       [ErrorDomain]
+       public enum FileError {
+               EXIST,
+               ISDIR,
+               ACCES,
+               NAMETOOLONG,
+               NOENT,
+               NOTDIR,
+               NXIO,
+               NODEV,
+               ROFS,
+               TXTBSY,
+               FAULT,
+               LOOP,
+               NOSPC,
+               NOMEM,
+               MFILE,
+               NFILE,
+               BADF,
+               INVAL,
+               PIPE,
+               AGAIN,
+               INTR,
+               IO,
+               PERM,
+               NOSYS,
+               FAILED
+       }
+
        public enum FileTest {
                IS_REGULAR,
                IS_SYMLINK,
@@ -1315,11 +1373,11 @@ namespace GLib {
 
        [CCode (cprefix = "g_file_", cheader_filename = "glib/gstdio.h")]
        public struct FileUtils {
-               public static bool get_contents (string! filename, out string contents, out long length, out Error error);
-               public static bool set_contents (string! filename, string contents, long length, out Error error);
+               public static bool get_contents (string! filename, out string contents, out long length) throws FileError;
+               public static bool set_contents (string! filename, string contents, long length) throws FileError;
                public static bool test (string filename, FileTest test);
-               public static int open_tmp (string tmpl, out string name_used, out Error error);
-               public static string read_link (string filename, out Error error);
+               public static int open_tmp (string tmpl, out string name_used) throws FileError;
+               public static string read_link (string filename) throws FileError;
                
                [CCode (cname = "g_rename")]
                public static int rename (string oldfilename, string newfilename);
@@ -1332,7 +1390,7 @@ namespace GLib {
 
        [ReferenceType (free_function = "g_dir_close")]
        public struct Dir {
-               public static Dir open (string filename, uint _flags, out Error error);
+               public static Dir open (string filename, uint _flags) throws FileError;
                public weak string read_name ();
                
                [CCode (cname = "g_mkdir")]
@@ -1343,7 +1401,7 @@ namespace GLib {
        
        [ReferenceType (free_function = "g_mapped_file_free")]
        public struct MappedFile {
-               public MappedFile (string filename, bool writable, out Error error);
+               public MappedFile (string filename, bool writable) throws FileError;
                public void free ();
                public long get_length ();
                [NoArrayLength]
@@ -1366,18 +1424,32 @@ namespace GLib {
 
        /* Shell-related Utilities */
 
+       [ErrorDomain]
+       public enum ShellError {
+               BAD_QUOTING,
+               EMPTY_STRING,
+               FAILED
+       }
+
        public struct Shell {
-               public static bool parse_argv (string! command_line, out int argcp, out string[] argvp, out Error error);
+               public static bool parse_argv (string! command_line, out int argcp, out string[] argvp) throws ShellError;
                public static string! quote (string! unquoted_string);
-               public static string! unquote (string! quoted_string, out Error error);
+               public static string! unquote (string! quoted_string) throws ShellError;
        }
 
        /* Commandline option parser */
 
+       [ErrorDomain]
+       public enum OptionError {
+               UNKNOWN_OPTION,
+               BAD_VALUE,
+               FAILED
+       }
+
        [ReferenceType (free_function = "g_option_context_free")]
        public struct OptionContext {
                public OptionContext (string parameter_string);
-               public bool parse (out string[] argv, out Error error);
+               public bool parse (out string[] argv) throws OptionError;
                public void set_help_enabled (bool help_enabled);
                [NoArrayLength ()]
                public void add_main_entries (OptionEntry[] entries, string translation_domain);
@@ -1421,6 +1493,7 @@ namespace GLib {
 
        /* Perl-compatible regular expressions */
 
+       [ErrorDomain]
        public enum RegexError {
                COMPILE,
                OPTIMIZE,
@@ -1461,7 +1534,7 @@ namespace GLib {
 
        [ReferenceType (dup_function = "g_regex_ref", free_function = "g_regex_unref")]
        public struct Regex {
-               public Regex (string! pattern, RegexCompileFlags compile_options = 0, RegexMatchFlags match_options = 0, out Error error = null);
+               public Regex (string! pattern, RegexCompileFlags compile_options = 0, RegexMatchFlags match_options = 0) throws RegexError;
                public string! get_pattern ();
                public int get_max_backref ();
                public int get_capture_count ();
@@ -1469,19 +1542,19 @@ namespace GLib {
                public string! escape_string (string! string, int length = -1);
                public static bool match_simple (string! pattern, string! string, RegexCompileFlags compile_options = 0, RegexMatchFlags match_options = 0);
                public bool match (string! string, RegexMatchFlags match_options = 0, out MatchInfo match_info = null);
-               public bool match_full (string! string, long string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null, out Error error = null);
+               public bool match_full (string! string, long string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null) throws RegexError;
                public bool match_all (string! string, RegexMatchFlags match_options = 0, out MatchInfo match_info = null);
-               public bool match_all_full (string! string, long string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null, out Error error = null);
+               public bool match_all_full (string! string, long string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null) throws RegexError;
                [NoArrayLength]
                public static string[] split_simple (string! pattern, string! string, RegexCompileFlags compile_options = 0, RegexMatchFlags match_options = 0);
                [NoArrayLength]
                public string[] split (string! string, RegexMatchFlags match_options = 0);
                [NoArrayLength]
-               public bool split_full (string! string, long string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, int max_tokens = 0, out Error error = null);
-               public string replace (string! string, long string_len, int start_position, string! replacement, RegexMatchFlags match_options = 0, out Error error = null);
-               public string replace_literal (string! string, long string_len, int start_position, string! replacement, RegexMatchFlags match_options = 0, out Error error = null);
-               public string replace_eval (string! string, long string_len, int start_position, RegexMatchFlags match_options = 0, RegexEvalCallback eval, pointer user_data, out Error error = null);
-               public static bool check_replacement (out bool has_references = null, out Error error = null);
+               public bool split_full (string! string, long string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, int max_tokens = 0) throws RegexError;
+               public string replace (string! string, long string_len, int start_position, string! replacement, RegexMatchFlags match_options = 0) throws RegexError;
+               public string replace_literal (string! string, long string_len, int start_position, string! replacement, RegexMatchFlags match_options = 0) throws RegexError;
+               public string replace_eval (string! string, long string_len, int start_position, RegexMatchFlags match_options = 0, RegexEvalCallback eval, pointer user_data) throws RegexError;
+               public static bool check_replacement (out bool has_references = null) throws RegexError;
        }
 
        public static delegate bool RegexEvalCallback (MatchInfo match_info, String result, pointer user_data);
@@ -1491,10 +1564,10 @@ namespace GLib {
                public weak Regex get_regex ();
                public weak string get_string ();
                public bool matches ();
-               public bool next (out Error error = null);
+               public bool next () throws RegexError;
                public int get_match_count ();
                public bool is_partial_match ();
-               public string! expand_references (string! string_to_expand, out Error error = null);
+               public string! expand_references (string! string_to_expand) throws RegexError;
                public string fetch (int match_num);
                public bool fetch_pos (int match_num, out int start_pos, out int end_pos);
                public weak string fetch_named (string! name);
@@ -1504,7 +1577,17 @@ namespace GLib {
        }
 
        /* Simple XML Subset Parser */
-       
+
+       [ErrorDomain]
+       public enum MarkupError {
+               BAD_UTF8,
+               EMPTY,
+               PARSE,
+               UNKNOWN_ELEMENT,
+               UNKNOWN_ATTRIBUTE,
+               INVALID_CONTENT
+       }
+
        [CCode (cprefix = "G_MARKUP_")]
        public enum MarkupParseFlags {
                TREAT_CDATA_AS_TEXT
@@ -1513,17 +1596,17 @@ namespace GLib {
        [ReferenceType (free_function = "g_markup_parse_context_free")]
        public struct MarkupParseContext {
                public MarkupParseContext (MarkupParser parser, MarkupParseFlags _flags, pointer user_data, DestroyNotify user_data_dnotify);
-               public bool parse (string text, long text_len, out Error error);
+               public bool parse (string text, long text_len) throws MarkupError;
        }
        
        [NoArrayLength]
-       public static delegate void MarkupParserStartElementFunc (MarkupParseContext context, string element_name, string[] attribute_names, string[] attribute_values, pointer user_data, out Error error);
+       public static delegate void MarkupParserStartElementFunc (MarkupParseContext context, string element_name, string[] attribute_names, string[] attribute_values, pointer user_data) throws MarkupError;
        
-       public static delegate void MarkupParserEndElementFunc (MarkupParseContext context, string element_name, pointer user_data, out Error error);
+       public static delegate void MarkupParserEndElementFunc (MarkupParseContext context, string element_name, pointer user_data) throws MarkupError;
        
-       public static delegate void MarkupParserTextFunc (MarkupParseContext context, string text, ulong text_len, pointer user_data, out Error error);
+       public static delegate void MarkupParserTextFunc (MarkupParseContext context, string text, ulong text_len, pointer user_data) throws MarkupError;
        
-       public static delegate void MarkupParserPassthroughFunc (MarkupParseContext context, string passthrough_text, ulong text_len, pointer user_data, out Error error);
+       public static delegate void MarkupParserPassthroughFunc (MarkupParseContext context, string passthrough_text, ulong text_len, pointer user_data) throws MarkupError;
        
        public static delegate void MarkupParserErrorFunc (MarkupParseContext context, Error error, pointer user_data);
        
@@ -1543,47 +1626,57 @@ namespace GLib {
        }
 
        /* Key-value file parser */
-       
+
+       [ErrorDomain]
+       public enum KeyFileError {
+               UNKNOWN_ENCODING,
+               PARSE,
+               NOT_FOUND,
+               KEY_NOT_FOUND,
+               GROUP_NOT_FOUND,
+               INVALID_VALUE
+       }
+
        [ReferenceType (free_function = "g_key_file_free")]
        public struct KeyFile {
                public KeyFile ();
                public void set_list_separator (char separator);
-               public bool load_from_file (string! file, KeyFileFlags @flags, out Error error);
-               public bool load_from_data (string! data, ulong length, KeyFileFlags @flags, out Error error);
-               public bool load_from_data_dirs (string! file, out string full_path, KeyFileFlags @flags, out Error error);
-               public string to_data (out ulong length, out Error error);
+               public bool load_from_file (string! file, KeyFileFlags @flags) throws KeyFileError;
+               public bool load_from_data (string! data, ulong length, KeyFileFlags @flags) throws KeyFileError;
+               public bool load_from_data_dirs (string! file, out string full_path, KeyFileFlags @flags) throws KeyFileError;
+               public string to_data (out ulong length) throws KeyFileError;
                public string get_start_group ();
                public string[] get_groups (out ulong length);
-               public string[] get_keys (string! group_name, out ulong length, out Error error);
+               public string[] get_keys (string! group_name, out ulong length) throws KeyFileError;
                public bool has_group (string! group_name);
-               public bool has_key (string! group_name, string! key, out Error error);
-               public string get_value (string! group_name, string! key, out Error error);
-               public string get_string (string! group_name, string! key, out Error error);
-               public string get_locale_string (string! group_name, string! key, string! locale, out Error error);
-               public bool get_boolean (string! group_name, string! key, out Error error);
-               public int get_integer (string! group_name, string! key, out Error error);
-               public double get_double (string! group_name, string! key, out Error error);
-               public string[] get_string_list (string! group_name, string! key, out ulong length, out Error error);
-               public string[] get_locale_string_list (string! group_name, string! key, string! locale, out ulong length, out Error error);
-               public bool[] get_boolean_list (string! group_name, string! key, out ulong length, out Error error);
-               public int[] get_integer_list (string! group_name, string! key, out ulong length, out Error error);
-               public double[] get_double_list (string! group_name, string! key, out ulong length, out Error error);
-               public string get_comment (string! group_name, string! key, out Error error);
-               public void set_value (string! group_name, string! key, string! value, out Error error);
-               public void set_string (string! group_name, string! key, string! string, out Error error);
-               public void set_locale_string (string! group_name, string! key, string! locale, string! string, out Error error);
-               public void set_boolean (string! group_name, string! key, bool value, out Error error);
-               public void set_integer (string! group_name, string! key, int value, out Error error);
-               public void set_double (string! group_name, string! key, double value, out Error error);
+               public bool has_key (string! group_name, string! key) throws KeyFileError;
+               public string get_value (string! group_name, string! key) throws KeyFileError;
+               public string get_string (string! group_name, string! key) throws KeyFileError;
+               public string get_locale_string (string! group_name, string! key, string! locale) throws KeyFileError;
+               public bool get_boolean (string! group_name, string! key) throws KeyFileError;
+               public int get_integer (string! group_name, string! key) throws KeyFileError;
+               public double get_double (string! group_name, string! key) throws KeyFileError;
+               public string[] get_string_list (string! group_name, string! key, out ulong length) throws KeyFileError;
+               public string[] get_locale_string_list (string! group_name, string! key, string! locale, out ulong length) throws KeyFileError;
+               public bool[] get_boolean_list (string! group_name, string! key, out ulong length) throws KeyFileError;
+               public int[] get_integer_list (string! group_name, string! key, out ulong length) throws KeyFileError;
+               public double[] get_double_list (string! group_name, string! key, out ulong length) throws KeyFileError;
+               public string get_comment (string! group_name, string! key) throws KeyFileError;
+               public void set_value (string! group_name, string! key, string! value) throws KeyFileError;
+               public void set_string (string! group_name, string! key, string! string) throws KeyFileError;
+               public void set_locale_string (string! group_name, string! key, string! locale, string! string) throws KeyFileError;
+               public void set_boolean (string! group_name, string! key, bool value) throws KeyFileError;
+               public void set_integer (string! group_name, string! key, int value) throws KeyFileError;
+               public void set_double (string! group_name, string! key, double value) throws KeyFileError;
                public void set_string_list (string! group_name, string! key);
                public void set_locale_string_list (string! group_name, string! key, string! locale);
                public void set_boolean_list (string! group_name, string! key, bool[] list, ulong length);
                public void set_integer_list (string! group_name, string! key, int[] list, ulong length);
                public void set_double_list (string! group_name, string! key, double[] list, ulong length);
-               public void set_comment (string! group_name, string! key, string! comment, out Error error);
-               public void remove_group (string! group_name, out Error error);
-               public void remove_key (string! group_name, string! key, out Error error);
-               public void remove_comment (string! group_name, string! key, out Error error);
+               public void set_comment (string! group_name, string! key, string! comment) throws KeyFileError;
+               public void remove_group (string! group_name) throws KeyFileError;
+               public void remove_key (string! group_name, string! key) throws KeyFileError;
+               public void remove_comment (string! group_name, string! key) throws KeyFileError;
        }
        
        [CCode (cprefix = "G_KEY_FILE_")]
index fcc5fd155965a5662a88a352b446b6317fe78e12..a4a4688ad037f9b4ce61c1bd64a4e3fea554cd05 100644 (file)
@@ -50,38 +50,40 @@ public class Vala.GIdlParser : CodeVisitor {
        }
        
        private void parse_file (SourceFile! source_file) {
-               Error error = null;
-               
                string metadata_filename = "%s.metadata".printf (source_file.filename.ndup (source_file.filename.size () - ".gidl".size ()));
                
                codenode_attributes_map = new HashTable.full (str_hash, str_equal, g_free, g_free);
                
                if (FileUtils.test (metadata_filename, FileTest.EXISTS)) {
-                       string metadata;
-                       long metadata_len;
-                       FileUtils.get_contents (metadata_filename, out metadata, out metadata_len, out error);
-                       
-                       foreach (string line in metadata.split ("\n")) {
-                               var line_parts = line.split (" ", 2);
-                               if (line_parts[0] == null) {
-                                       continue;
-                               }
+                       try {
+                               string metadata;
+                               long metadata_len;
+                               FileUtils.get_contents (metadata_filename, out metadata, out metadata_len);
                                
-                               codenode_attributes_map.insert (line_parts[0], line_parts[1]);
+                               foreach (string line in metadata.split ("\n")) {
+                                       var line_parts = line.split (" ", 2);
+                                       if (line_parts[0] == null) {
+                                               continue;
+                                       }
+                                       
+                                       codenode_attributes_map.insert (line_parts[0], line_parts[1]);
+                               }
+                       } catch (FileError e) {
+                               Report.error (null, "Unable to read metadata file: %s".printf (e.message));
                        }
                }
        
-               var modules = Idl.parse_file (source_file.filename, out error);
-               
-               if (error != null) {
-                       stdout.printf ("error parsing GIDL file: %s\n", error.message);
-               }
-               
-               current_source_reference = new SourceReference (source_file);
-               
-               foreach (IdlModule module in modules) {
-                       var ns = parse_module (module);
-                       source_file.add_namespace (ns);
+               try {
+                       var modules = Idl.parse_file (source_file.filename);
+                       
+                       current_source_reference = new SourceReference (source_file);
+                       
+                       foreach (IdlModule module in modules) {
+                               var ns = parse_module (module);
+                               source_file.add_namespace (ns);
+                       }
+               } catch (MarkupError e) {
+                       stdout.printf ("error parsing GIDL file: %s\n", e.message);
                }
        }
 
index d0d16f88b8364e11387403efc32b761ea97493c8..6fd4f63526b88740c4159ea1f83600b388eda224 100644 (file)
@@ -172,17 +172,17 @@ class Vala.VAPIGen {
        }
        
        static int main (string[] args) {
-               Error err = null;
-       
-               var opt_context = new OptionContext ("- Vala API Generator");
-               opt_context.set_help_enabled (true);
-               opt_context.add_main_entries (options, null);
-               opt_context.parse (out args, out err);
-               
-               if (err != null) {
+               try {
+                       var opt_context = new OptionContext ("- Vala API Generator");
+                       opt_context.set_help_enabled (true);
+                       opt_context.add_main_entries (options, null);
+                       opt_context.parse (out args);
+               } catch (OptionError e) {
+                       stdout.printf ("%s\n", e.message);
+                       stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
                        return 1;
                }
-               
+
                if (sources == null) {
                        stderr.printf ("No source file specified.\n");
                        return 1;