| View previous topic :: View next topic |
| Author |
Message |
JD Guest
|
Posted: Fri Jan 30, 2004 10:29 pm Post subject: Re: rethrowing VCL exceptions |
|
|
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote:
| Quote: | [...] "You cannot use throw to reraise an exception that was
caught within VCL code"
|
Your example does not catch an exception thrown by the VCL.
What you wanted to do was something like this which of course
should not work:
try
{
try
{
SomeObject->SomeMethodThatThrowsAnException();
}
catch(const Exception& ex)
{
ShowMessage("Inner catch: " + ex.Message);
throw;
}
}
catch(const Exception& ex)
{
ShowMessage("Outer catch: " + ex.Message);
}
However, you can work around it:
try
{
try
{
SomeObject->SomeMethodThatThrowsAnException();
}
catch( Exception& ex )
{
throw Exception("Inner catch : " + ex.Message);
}
}
catch( Exception& ex )
{
ShowMessage("Outer catch: " + ex.Message);
}
~ JD
|
|
| Back to top |
|
 |
nicolasr Guest
|
Posted: Fri Jan 30, 2004 11:19 pm Post subject: rethrowing VCL exceptions |
|
|
Hi,
while working with VCL exceptions I found the following
in the online help:
"You cannot use throw to reraise an exception that was
caught within VCL code"
I somehow seem to misunderstand what's the point here.
I tried the following code
try
{
try
{
throw Exception("Hello");
}
catch(const Exception& ex)
{
ShowMessage("Inner catch: " + ex.Message);
throw;
}
}
catch(const Exception& ex)
{
ShowMessage("Outer catch: " + ex.Message);
}
which works as I expected.
Could anyone tell me what is meant by the above statement?
thanks,
Nick
|
|
| Back to top |
|
 |
Garfield Guest
|
Posted: Sat Jan 31, 2004 6:17 am Post subject: Re: rethrowing VCL exceptions |
|
|
Hi:
JD is true!
I try it :
//NON VCL
try
{
try
{
throw Exception("Hello");
}
catch(const Exception& ex)
{
ShowMessage("Inner catch: " + ex.Message);
throw;
}
}
catch(const Exception& ex)
{
ShowMessage("Outer catch: " + ex.Message);
}
//Use VCL
try
{
try
{
TListView *lv;
lv->AddItem("",NULL);
}
catch( Exception& ex )
{
throw Exception("Inner catch : " + ex.Message);
}
}
catch( Exception& ex )
{
ShowMessage("Outer catch: " + ex.Message);
}
"JD" <nospam (AT) nospam (DOT) com> дÈëÓʼþ news:401ae8dd$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote:
[...] "You cannot use throw to reraise an exception that was
caught within VCL code"
Your example does not catch an exception thrown by the VCL.
What you wanted to do was something like this which of course
should not work:
try
{
try
{
SomeObject->SomeMethodThatThrowsAnException();
}
catch(const Exception& ex)
{
ShowMessage("Inner catch: " + ex.Message);
throw;
}
}
catch(const Exception& ex)
{
ShowMessage("Outer catch: " + ex.Message);
}
However, you can work around it:
try
{
try
{
SomeObject->SomeMethodThatThrowsAnException();
}
catch( Exception& ex )
{
throw Exception("Inner catch : " + ex.Message);
}
}
catch( Exception& ex )
{
ShowMessage("Outer catch: " + ex.Message);
}
~ JD
|
|
|
| Back to top |
|
 |
nicolasr Guest
|
Posted: Sun Feb 01, 2004 2:26 am Post subject: Re: rethrowing VCL exceptions |
|
|
thanks JD and Garfield!
Just in case someone knows: What are the details why I can't
rethrow a VCL exception? When I do it I get an AV, so I assume
it has something to do with the exception object lifetimes?
I can live without knowing the details, would be interesting to know,
though.
thanks for the help,
Nick
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sun Feb 01, 2004 5:33 am Post subject: Re: rethrowing VCL exceptions |
|
|
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote
| Quote: | Just in case someone knows: What are the details why I
can't rethrow a VCL exception?
|
Probably has something to do with the fact that it is being originally
thrown by Delphi code, not C++ code. Different languages, different rules.
Gambit
|
|
| Back to top |
|
 |
|