Re: [Vala] How to ignore exceptions?
- From: PCMan <pcman tw gmail com>
- To: JM <interflug1 gmx net>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] How to ignore exceptions?
- Date: Sun, 30 Oct 2011 22:00:56 +0800
Is it possible to suppress these compiler warnings and not turn off all of
the warnings at the same time?
On Sun, Oct 30, 2011 at 9:04 PM, JM <interflug1 gmx net> wrote:
just don't use the try-catch block:
str1 = kf.get_string(group, key);
str2 = kf.get_string(group, key);
str3 = kf.get_string(group, key);
This will give you a warning during compile but should be the thing you
are looking for.
jm.
Am Sonntag, den 30.10.2011, 19:04 +0800 schrieb PCMan:
Hi all,
I started using Vala recently and I'm confused by exception handling in
Vala.
I'm quite used to write C/GObject code and handles GError.
However, with exceptions, flow-control becomes quite different.
For example, I'm reading values from a KeyFile.
With C/glib, I can pass NULL GError* pointer to g_key_file_get_string()
to
ignore any errors.
If the errors are not critical for my program, it's safe to ignore them
all
like this.
str1 = g_key_file_get_string(kf, group, key, NULL);
str2 = g_key_file_get_string(kf, group, key, NULL);
str3 = g_key_file_get_string(kf, group, key, NULL);
if( !str1 && !str2 && !str3)
return FALSE;
With Vala, I cannot do this. If I use try/catch, things are totally
different.
try {
str1 = kf.get_string(group, key);
str2 = kf.get_string(group, key);
str3 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
// If anyone of the preceding calls fails, we get here.
// then I cannot continue getting the remaining strings from key
file.
}
If get str1 fails, the excution jumps to catch() block, and I cannot
continue reading str2 and str3.
Of course I can do this:
try {
str1 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
}
try {
str2 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
}
try {
str3 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
}
Apparently, this looks even worse then its C/glib counterpart.
So, how to ignore the GErrors/vala excaptions anyways?
Thank you all.
_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]