Re: [Vala] possible bug with exception handling



guess I should check bugzilla first:
http://bugzilla.gnome.org/show_bug.cgi?id=546043

On Sat, Sep 6, 2008 at 5:21 PM, Cliff Brake <cliff brake gmail com> wrote:
I have the following Vala code:

using GLib;

public errordomain TestError {
   FAILED
}

static bool test_func() throws TestError
{
   debug ("test function");
   throw new TestError.FAILED ("test error");
   return  true;
}

void main(string[] args)
{
   try {
       bool ret = test_func();
       assert(ret);
   } catch (TestError e) {
       debug ("this message is printed %s", e.message);
   }

   try {
       assert(test_func());
   } catch (TestError e) {
       debug ("this message never gets printed, even though the
exception is handled %s", e.message);
   }
}

Which produces the following output:
cbrake happy:/build/tmp/vala_stat$ ./test_Error
** (process:14891): DEBUG: test_Error.vala:10: test function
** (process:14891): DEBUG: test_Error.vala:21: this message is printed
test error
** (process:14891): DEBUG: test_Error.vala:10: test function
**
** ERROR:(test_Error.c:61):_main: assertion failed: (test_func (&inner_error))
Aborted


So, it seems that if I wrap a function that can throw an exception in
assert(), the exception code does not get generated properly:

below is the C code:

static void _main (char** args, int args_length1) {
       GError * inner_error;
       inner_error = NULL;
       {
               gboolean ret;
               ret = test_func (&inner_error);
               if (inner_error != NULL) {
                       if (inner_error->domain == TEST_ERROR) {
                               goto __catch0_test_error;
                       }
                       g_critical ("file %s: line %d: uncaught error: %s", __FILE__,
__LINE__, inner_error->message);
                       g_clear_error (&inner_error);
               }
               g_assert (ret);
       }
       goto __finally0;
       __catch0_test_error:
       {
               GError * e;
               e = inner_error;
               inner_error = NULL;
               {
                       g_debug ("test_Error.vala:21: this message is printed %s", e->message);
                       (e == NULL ? NULL : (e = (g_error_free (e), NULL)));
               }
       }
       __finally0:
       ;
       {
               g_assert (test_func (&inner_error));
       }
       goto __finally1;
       __catch1_test_error:
       {
               GError * e;
               e = inner_error;
               inner_error = NULL;
               {
                       g_debug ("test_Error.vala:27: this message never gets printed, even
though the exception is handled %s", e->message);
                       (e == NULL ? NULL : (e = (g_error_free (e), NULL)));
               }
       }
       __finally1:
       ;
}

Is this a bug -- if so I'd be glad to log it.

Thanks,
Cliff

--
=======================
Cliff Brake
http://bec-systems.com




-- 
=======================
Cliff Brake
http://bec-systems.com



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