gsettings - How to handle errors while using Glib.Settings in Vala? -


I am using Glib.Settings in my Vala application. And I have to make sure that my program will work properly even if the schema or key is not available. So I've added an attempt / catch block, but if I'm using the key that does not exist, the program segfaults. As I understand, it does not even reach the catch statement. Here is the function that uses the settings:

  GLib.Settings settings; String token = ""; Try {settings = new GLib.Settings (my_scheme); Tokens = settings.get_string ("token1"); } Hold (error e) {print ("error"); Token = ""; } Return token;  

and program output is:

  (Main: 27194): GLib-GIO-ERROR **: Settings key in schema 'my_scheme' Token1 'trace / breakpoints trap (core dump)  

(Of course I am using my real scheme instead of my_scheme) Can you suggest me where I am wrong? Methods, code in get_string

GLib.Settings > Do not throw exceptions, they call abort inside the library. This is not an ideal design, but you can not do anything about it.

In this case, correct your schema to work correctly, / usr / share / glib-2.0 / schema and on that directory (as code) Glib-compile-schemas .

Vala has examined only the exceptions, therefore, the opposite method of C # declares should declare that it will throw, or it is not possible to do so. You can always double check to see Wadakock or VAPI.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -