[Vala] Weird error handling



Hello!

While working on project I discovered invalid (in my opinion) error
handling. I wrote simple program (code below), which demonstrate, that
"catch" clause in some_function() catch errors threw from this function. On
the output program gives

a 'B' error and an 'A' error

but it should display

an 'A' error

Maybe it's typical error handling model for Vala however I haven't notice
that while reading tutorial. I use Vala compiler v 0.12.1.

**** SAMPLE PROGRAM: ***


public errordomain SomeError
{
A,
B
}

void some_function () throws SomeError
{
try
{
 if (2 != 1)
{
throw new SomeError.A ("an \'A\' error");
 }
}
catch (GLib.Error error)
 {
throw new SomeError.B ("a \'B\' error and " + error.message);
 }
}

int main (string[] arguments)
{
 try
{
some_function ();
 }
catch (SomeError error)
 {
stdout.printf ("%s\n", error.message);
}

return 0;
}


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