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



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)?


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