After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 559971 - a compound line of code with a function that might throw followed by a conditional throw does not work
a compound line of code with a function that might throw followed by a condit...
Status: RESOLVED DUPLICATE of bug 475922
Product: vala
Classification: Core
Component: general
0.5.x
Other All
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-11-09 05:52 UTC by Dwight Schauer
Modified: 2009-01-17 23:17 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Dwight Schauer 2008-11-09 05:52:29 UTC
Please describe the problem:
if I have a function called foo that may throw then:

    int b = foo();
    int a = 5/b;
    if (-1 < 1) throw new dee.CODE_1A("Error #2");

works as expected. However:

   int a = 5/foo();
   if (-1 < 1) throw new dee.CODE_1A("Error #2");

does not work as expected.


Steps to reproduce:
compile and run this code:
-------------------------
using GLib;

errordomain dee {
  CODE_1A;
}
int foo() throws dee
{
  if (-1 < 1) throw new dee.CODE_1A("Foo");
  return 7;
}
int main (string[] args)
{
  try
  {
    stdout.printf("Ok, got here\n");
    int b = foo();
    int a = 5/b;
    if (-1 < 1) throw new dee.CODE_1A("Error #2");
    stdout.printf("Ok, but not here\n");
  }
  catch (Error ex)
  {
    stdout.printf("Ex: %s\n",ex.message);
  }
  try
  {
    stdout.printf("Ok, got here\n");
    int a = 5/foo();
    if (-1 < 1) throw new dee.CODE_1A("Error #2");
    stdout.printf("Ok, but not here\n");
  }
  catch (Error ex)
  {
    stdout.printf("Ex: %s\n",ex.message);
  }
  return 0;
}


Actual results:
Ok, got here
Ex: Foo
Ok, got here
Floating point exception


Expected results:
Ok, got here
Ex: Foo
Ok, got here
Ex: Foo


Does this happen every time?
Yes.

Other information:
I've found a couple other catch/throw vala compiler oddities as well.

throw 1; // compiled by vala without any trouble but causes a 
Segmentation fault when run.

Multiple catches are compiled by vala with no error, but generate bad C code that can't be compiled.
Comment 1 Jürg Billeter 2009-01-17 23:17:59 UTC
Thanks for taking the time to report this bug.
This particular bug has already been reported into our bug tracking system, but we are happy to tell you that the problem has already been fixed. It should be solved in the next software version. You may want to check for a software upgrade.


*** This bug has been marked as a duplicate of 475922 ***