Board index » cppbuilder » Why does my EConvertException not reach the catch(...)-block?

Why does my EConvertException not reach the catch(...)-block?


2003-10-12 04:52:26 PM
cppbuilder28
Having the following snippet
try {
TDateTime date_time(2003, 01, 32); // invalid day
}
catch(...) {
Application->MessageBox("Error converting Date", "Error", MB_OK);
}
the catch(...) block is not reached when running in an (obvious)
EConvertError-exception.
The exception rises, C++Builder displays an appropriate MessageBox (in
the de{*word*81}), but instead of reaching the catch(...) block the
application displays an own messagebox with a message text 'Invalid
argument for coding date' (translated) and neither the catch() block
was reached nor the code behind.
What happened and how can I changed this behaviour.
Thanks a lot,
Michael
 
 

Re:Why does my EConvertException not reach the catch(...)-block?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
You need to catch a VCL exception:
catch( Exception& E )
Todd
 

Re:Why does my EConvertException not reach the catch(...)-block?

"Todd Brylski" < XXXX@XXXXX.COM >wrote in message news:3f891d92$ XXXX@XXXXX.COM ...
Quote
<M_R>wrote in message news: XXXX@XXXXX.COM ...

You need to catch a VCL exception:

catch( Exception& E )
or: catch( EConvertError& E )
Todd
 

{smallsort}

Re:Why does my EConvertException not reach the catch(...)-block?

Sorry,
trying
try {
TDateTime date_time(2003, 01, 32);
}
catch(Exception& E) {
Application->MessageBox("Error converting Date", "Error", MB_OK);
}
does not change anything on my problem.
Michael
Exception& E"Todd Brylski" < XXXX@XXXXX.COM >schrieb:
Quote
"Todd Brylski" < XXXX@XXXXX.COM >wrote in message news:3f891d92$ XXXX@XXXXX.COM ...
><M_R>wrote in message news: XXXX@XXXXX.COM ...
>
>You need to catch a VCL exception:
>
>catch( Exception& E )

or: catch( EConvertError& E )

Todd

 

Re:Why does my EConvertException not reach the catch(...)-block?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Quote
Sorry,

trying

try {
TDateTime date_time(2003, 01, 32);
}
catch(Exception& E) {
Application->MessageBox("Error converting Date", "Error", MB_OK);
}

does not change anything on my problem.
This catches as expected for me in BCB5.
Todd
 

Re:Why does my EConvertException not reach the catch(...)-block?

Quote
This catches as expected for me in BCB5.

I'm using BCB5 too.
I agree they should work (same as catch(...) ), but they don't.
(Perhaps there is an option which has to set somewhere!?)
Did you try this out?
Thanks,.
Michael
 

Re:Why does my EConvertException not reach the catch(...)-block?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Quote
the catch(...) block is not reached when running in an (obvious)
EConvertError-exception.
Which version of BCB are you using? BB6 changed the rules on how '...'
handles VCL exceptions.
Either way, you should always catch actual VCL exceptions instead of using
'...' regardless of version:
catch(EConvertError&)
or
catch(Exception&)
Gambit
 

Re:Why does my EConvertException not reach the catch(...)-block?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Quote
I agree they should work (same as catch(...) ), but they don't.
(Perhaps there is an option which has to set somewhere!?)
Make sure you have exception handling enabled in the Project Options to
begin with.
Quote
Did you try this out?
He said he did.
Gambit
 

Re:Why does my EConvertException not reach the catch(...)-block?

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message news:3f89d25e$ XXXX@XXXXX.COM ...
Quote

<M_R>wrote in message news: XXXX@XXXXX.COM ...

>I agree they should work (same as catch(...) ), but they don't.
>(Perhaps there is an option which has to set somewhere!?)

Make sure you have exception handling enabled in the Project Options to
begin with.
I was going to suggest that (enabling exceptions) but if
they are not enabled the program won't compile anyway.
It will give a compiler error on the try statement.
Todd
 

Re:Why does my EConvertException not reach the catch(...)-block?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Quote
>This catches as expected for me in BCB5.
>

I'm using BCB5 too.
I agree they should work (same as catch(...) ), but they don't.
(Perhaps there is an option which has to set somewhere!?)

Did you try this out?
Yes, I had cut & pasted the actual code. It works.
catch(...) does not catch VCL exceptions.
VCL exceptions must be caught by a VCL exception class, by reference.
catch( Exception& E ) will catch all VCL exceptions.
All other VCL exceptions classes are derived from Exception class.
The settings are in Projects/Options/C++ tab.
If all else fails, put your code in the constructor of the main form
so it is the first code to run, to isolate it, and see what happens.
That's where I had pasted it.
Todd
 

Re:Why does my EConvertException not reach the catch(...)-block?

"Todd Brylski" < XXXX@XXXXX.COM >schrieb:
Quote
<M_R>wrote in message news: XXXX@XXXXX.COM ...
catch(...) does not catch VCL exceptions.
VCL exceptions must be caught by a VCL exception class, by reference.
Oh, interesting. I thought catch(...) would catch all not already
handled exceptions...
But this is not the problem: the exception is NOT catched inside the
catch(Exception &E) too.
Quote

catch( Exception& E ) will catch all VCL exceptions.
All other VCL exceptions classes are derived from Exception class.

The settings are in Projects/Options/C++ tab.
Yes, exceptions are enabled here: (Activate RTTI is checked,
activate Exceptions is checked, and Destructor-Call is checked;
place of occurence and quick exception-prologue are NOT checked).
(I'm using the german edition of BCB5, the option descriptions are
translated and might probably sound similar, but not equal to my
translations)
It is interesting that a messagebox occurs after the information of
the exception (from inside the de{*word*81}), saying 'invalid argument for
coding the date'. This messagebox has to be somewhere in BCB: it is
not inside my application...
Quote
If all else fails, put your code in the constructor of the main form
so it is the first code to run, to isolate it, and see what happens.
That's where I had pasted it.
When placing the code inside the constructor (instead of the
OnCreate-methode) after the de{*word*81}-information of the exception I
get a messagebox with a different content, with the following
translation:
'In Project ....exe an exception of class EExternalException occured.
Message 'External Exception C0000025' Process was stopped. Continue
with single statement or Start'
Perhaps the exception handling is done inside the
TDateTimer-constructor itself!?
Michael
Quote

Todd

 

Re:Why does my EConvertException not reach the catch(...)-block?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Quote
It is interesting that a messagebox occurs after the information
of the exception (from inside the de{*word*81}), saying 'invalid
argument for coding the date'. This messagebox has to be
somewhere in BCB: it is not inside my application...
The IDE's de{*word*81} is set up by default to intercept all exceptions before
the application does. Simply press F9 to pass the exception back to the
application for normal handling.
Gambit
 

Re:Why does my EConvertException not reach the catch(...)-block?

M_R <>writes:
Quote
"Todd Brylski" < XXXX@XXXXX.COM >schrieb:

><M_R>wrote in message news: XXXX@XXXXX.COM ...

>catch(...) does not catch VCL exceptions.
>VCL exceptions must be caught by a VCL exception class, by reference.

Oh, interesting. I thought catch(...) would catch all not already
handled exceptions...
catch(...) will catch any C++ exception, but VCL exceptions are not
C++. In old versions of BCB, that is why catch(...) did not catch VCL
exceptions, but this was considered a bug. In the current release of
BCB (version 6), and quite possibly in version 5 too, this was fixed,
and catch(...) should catch VCL exceptions.
To keep semantic behavior the same across older and newer versions of
BCB, it's still a good idea to catch VCL exceptions by their own base
class type rather than relying on (...).
Quote
But this is not the problem: the exception is NOT catched inside the
catch(Exception &E) too.
Hmmm, I don't know what to suggest. Sorry.
--
Chris (TeamB);
 

Re:Why does my EConvertException not reach the catch(...)-block?

"Chris Uzdavinis (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
catch(...) will catch any C++ exception, but VCL exceptions
are not C++. In old versions of BCB, that is why catch(...) did
not catch VCL exceptions, but this was considered a bug. In the
current release of BCB (version 6), and quite possibly in version
5 too, this was fixed, and catch(...) should catch VCL exceptions.
Actually, it is the other way around. Older versions did support '...' for
VCL exceptions, up to BCB5. BCB6 appears to have changed the rules to make
'...' not catch VCL exceptions anymore. At least, that is my take on it,
since they updated the WinMain() template to separate VCL and C++ exception
handling into different statements now.
Quote
To keep semantic behavior the same across older and newer
versions of BCB, it's still a good idea to catch VCL exceptions
by their own base class type rather than relying on (...).
I agree.
Gambit
 

Re:Why does my EConvertException not reach the catch(...)-block?

<M_R>wrote in message news: XXXX@XXXXX.COM ...
Go to: Tools/De{*word*81} Options.../Language Exceptions
Uncheck: 'Stop on Delphi Exceptions'
Quote
When placing the code inside the constructor (instead of the
OnCreate-methode)...
You should never use OnCreate event handler, it doesn't work predictably.
Use the constructor for all initializations.
Todd