[Vala] Can constructors throw errors, cascade?



Being new to both Vala and GObjects I hope you will forgive me if my
questions are obvious.

Is it acceptable for a constructor to throw an error.
ie.

                public ResourceFile.from_file (string rc_filename)  throws GLib.FileError {
                        string sz_data;
                        if (FileUtils.test (rc_filename, FileTest.IS_REGULAR)) {
                                if (!FileUtils.get_contents(rc_filename, out sz_data)) {
                                        throw new GLib.FileError.FAILED (_("could not load
%s.\n".printf(rc_filename)));
                                }
                                ResourceFile.from_data(sz_data); // Is this OK to cascade?
                        }
                }

Also, it is acceptable to cascade the constructor from above.

                public ResourceFile.from_data (string rc_data) {
                        GLib.Object (data: rc_data);
                }


If there's a better way, I would appreciate the lesson.

-- 
Regards,
-Brian



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