try catch weird effect 
Author Message
 try catch weird effect

Hello.
I am porting a DCOM server developed with VC60 into VC70
and I have a strange behaviour.  Whithin a try catch
block, when debugging the code, the cursor jumps to
unexpected lines (but does not execute these lines) and
then comes back to the correct line.
Here is what happens:
The code execute the if (1).  Once executed, the code
jumps in the if to return FALSE line (2) like if the
pointer is NULL (but it is not NULL) but does not execute
this line.  Then the cursor jumps at the end of the catch
(3), returns one line backward in the catch (4) but doen
not execute this line, then jumps at the end of the method
and execute the last return (5) (see code below).

-----------------
try
{
  if( (m_pSet = new CSitesSet) == NULL ) (1)
  {
    TRACE( "Create Site Set failed\n" );
    return FALSE; (2)
  }
catch( CDBException * E )
{
  ASSERT( FALSE );
  str.Format( "Exception raised: %s\n", E->m_strError );
  TRACE( str );
  E->Delete();
  return FALSE; (4)

Quote:
} (3)

return TRUE ; (5)
-----------------

I noticed that if I put an else to the if, the code
executes correctly but this piece of code works fine when
compiled with VC60.

Does anyone have an idea?  New settings that I should be
awared of?



Sun, 18 Sep 2005 21:58:19 GMT  
 try catch weird effect

Quote:

> [...]
> try
> {
>   if( (m_pSet = new CSitesSet) == NULL ) (1)
>   {
>     TRACE( "Create Site Set failed\n" );
>     return FALSE; (2)
>   }
> catch( CDBException * E )
> {
>   ASSERT( FALSE );
>   str.Format( "Exception raised: %s\n", E->m_strError );
>   TRACE( str );
>   E->Delete();
>   return FALSE; (4)
> } (3)

> return TRUE ; (5)
> [...]

  Please make sure you post the actual code you're
  experience this with (copy'n'paste). The above
  code misses a } before the catch. I doubt it would
  compile.

  Schobi

--

I'm Schobi at suespammers org



Mon, 19 Sep 2005 16:02:39 GMT  
 try catch weird effect
Hello Schobi

Yes, you are right.  However you can be sure that the '{'
is present in the original source code and is not the
cause of this behaviour.
Any idea on what's going on?
Thank you very much.

Quote:
>-----Original Message-----

>> [...]
>> try
>> {
>>   if( (m_pSet = new CSitesSet) == NULL ) (1)
>>   {
>>     TRACE( "Create Site Set failed\n" );
>>     return FALSE; (2)
>>   }
   {
>> catch( CDBException * E )
>> {
>>   ASSERT( FALSE );
>>   str.Format( "Exception raised: %s\n", E->m_strError );
>>   TRACE( str );
>>   E->Delete();
>>   return FALSE; (4)
>> } (3)

>> return TRUE ; (5)
>> [...]

>  Please make sure you post the actual code you're
>  experience this with (copy'n'paste). The above
>  code misses a } before the catch. I doubt it would
>  compile.

>  Schobi

>--

>I'm Schobi at suespammers org

>.



Tue, 20 Sep 2005 01:31:00 GMT  
 try catch weird effect

Quote:

> [...]
> Any idea on what's going on?

  You haven't turned on any optimizations, have
  you?

Quote:
> [...]

  Schobi

--

I'm Schobi at suespammers org



Tue, 20 Sep 2005 16:30:15 GMT  
 try catch weird effect
Hello Schobi,

No, optimization is disabled.  However C++ Exceptions are
enabled (switch /EHsc)

Thanks again,

Quote:
>-----Original Message-----

>> [...]
>> Any idea on what's going on?

>  You haven't turned on any optimizations, have
>  you?

>> [...]

>  Schobi

>--

>I'm Schobi at suespammers org

>.



Sun, 25 Sep 2005 23:02:09 GMT  
 try catch weird effect

Quote:

>Subject: Re: try catch weird effect

>No, optimization is disabled.  However C++ Exceptions are
>enabled (switch /EHsc)

>Thanks again,

>>-----Original Message-----

>>> [...]
>>> Any idea on what's going on?

>>  You haven't turned on any optimizations, have
>>  you?

>>> [...]

>>  Schobi

>>--

>>I'm Schobi at suespammers org

>>.

We've reproduced the issue.  The line number info is incorrect in a few
places, but it doesn't actually cause the code itself to function
improperly.  Major annoyance, absolutely.  But for now, just ignore what
the de{*filter*} is telling you about where you are, and notice that the
side-effects of the code itself are correct.

--
Kevin Frei & Charles Park
Visual C++
This posting is provided "as is" with no warranties, and confers no rights.
Void where prohibited.



Sat, 15 Oct 2005 02:23:30 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. TRY-CATCH vs. try-catch

2. try/catch VS TRY/CATCH

3. Can you catch CDBExection with try-catch keyword?

4. why {try catch} does not catch

5. Q: Why try catch cannot catch the exception

6. Using SHGetFileInfo to return icon handle produces weird effect

7. weird macro expansion effect

8. weird, weird and really weird?

9. Try catch blocks - can multiple methods share a single try/catch combination?

10. Exception Handling and CDatabase / CRecordset: try-catch( CDBException cdbe) vs. try-catch (...)

11. Try catch blocks - can multiple methods share a single try/catch combination?

12. try-catch-finally problem (I think?)

 

 
Powered by phpBB® Forum Software