BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

rethrowing VCL exceptions

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
JD
Guest





PostPosted: Fri Jan 30, 2004 10:29 pm    Post subject: Re: rethrowing VCL exceptions Reply with quote



"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





PostPosted: Fri Jan 30, 2004 11:19 pm    Post subject: rethrowing VCL exceptions Reply with quote



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





PostPosted: Sat Jan 31, 2004 6:17 am    Post subject: Re: rethrowing VCL exceptions Reply with quote



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





PostPosted: Sun Feb 01, 2004 2:26 am    Post subject: Re: rethrowing VCL exceptions Reply with quote

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





PostPosted: Sun Feb 01, 2004 5:33 am    Post subject: Re: rethrowing VCL exceptions Reply with quote


"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.