www.digitalmars.com         C & C++   DMDScript  

D - cannot go into try block

reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
The following will not compile, it give the followig error
: cannot goto into try block

class Test
{
 Object o;
 int c;

 Object failToCompile(  )
 {
  if ( o == null )
  {
   try
   {
    if ( c < 33 )


     if ( c == 0 ) { return null; }
    }
   }
   catch ( Exception e )
   {
   }
  }
  return o;
 }
}

curiously removing the if ( c== 0) allows it to compile, and in this
example removing the if (o==null) does not but in the original code (which
was more complex) it did.

as an aside, commenting out the return does not give a 'this function has a
missing return value' but this error
: cannot goto forward into different try block level
as opposed to
: failToCompile function expected to return a value of type Object

only seems to occur in member functions. if its not a member function then
removing the return will result in it compiling without error.

I have to admit to being confused by the error message I assume it internal
exception stuff or have I totally missed the meaning of the error message.

Mike.
Jan 22 2002
parent reply "Walter" <walter digitalmars.com> writes:
Ok, I'll check into it. Thanks! -Walter

"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
news:a2kqin$qp8$1 digitaldaemon.com...
 The following will not compile, it give the followig error
 : cannot goto into try block

 class Test
 {
  Object o;
  int c;

  Object failToCompile(  )
  {
   if ( o == null )
   {
    try
    {
     if ( c < 33 )


      if ( c == 0 ) { return null; }
     }
    }
    catch ( Exception e )
    {
    }
   }
   return o;
  }
 }

 curiously removing the if ( c== 0) allows it to compile, and in this
 example removing the if (o==null) does not but in the original code (which
 was more complex) it did.

 as an aside, commenting out the return does not give a 'this function has
a
 missing return value' but this error
 : cannot goto forward into different try block level
 as opposed to
 : failToCompile function expected to return a value of type Object

 only seems to occur in member functions. if its not a member function then
 removing the return will result in it compiling without error.

 I have to admit to being confused by the error message I assume it
internal
 exception stuff or have I totally missed the meaning of the error message.

 Mike.
Jan 22 2002
parent Ruslanas Abdrachimovas <anubis 03bar.ktu.lt> writes:
This problem could be resolved so:

[dmd\src\phobos\object.d]
remove line: "extern (C) static int printf(char *, ...);"
add    line: "import c.stdio;"

Then everything works OK. =]

How do think?

Walter wrote:

 Ok, I'll check into it. Thanks! -Walter
 
 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:a2kqin$qp8$1 digitaldaemon.com...
 
The following will not compile, it give the followig error
: cannot goto into try block

class Test
{
 Object o;
 int c;

 Object failToCompile(  )
 {
  if ( o == null )
  {
   try
   {
    if ( c < 33 )


     if ( c == 0 ) { return null; }
    }
   }
   catch ( Exception e )
   {
   }
  }
  return o;
 }
}

curiously removing the if ( c== 0) allows it to compile, and in this
example removing the if (o==null) does not but in the original code (which
was more complex) it did.

as an aside, commenting out the return does not give a 'this function has
a
missing return value' but this error
: cannot goto forward into different try block level
as opposed to
: failToCompile function expected to return a value of type Object

only seems to occur in member functions. if its not a member function then
removing the return will result in it compiling without error.

I have to admit to being confused by the error message I assume it
internal
exception stuff or have I totally missed the meaning of the error message.

Mike.
Jan 30 2002