Re: [Vala] Can I have multiple catch blocks in Vala?



On Tue, 2016-12-06 at 13:07 +0200, abbuyy wrote:
I have read documentation for KeyFile.load_from_file ( 
https://valadoc.org/glib-2.0/GLib.KeyFile.load_from_file.html )**and 
there is such sentence: If the file could not be loaded then throws
is 
set to either a FileError or KeyFileError. So, how to handle
exception? 
Like so:

             try {
                 file.load_from_file (app.FILE_PATH, 
KeyFileFlags.KEEP_COMMENTS);
             } catch (FileError e) {
                 stdout.printf("Error: %s\n", e.message);
             }
             catch (KeyFileError e) {
                 stdout.printf("Error: %s\n", e.message);
             }
Or better just write if (file.load_from_file (…) == true)?

If you only test the return value Vala will complain about an uncaught
exception.  The return value is really meant as a convenience for C,
not higher-level languages.


-Evan


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]