473,320 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

using default exception in catch(...)

Is there anyway that I can get at the actual exception in a catch(...)?

Dec 6 '06 #1
16 3767
* jo*********@gmail.com:
Is there anyway that I can get at the actual exception in a catch(...)?
throw

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 6 '06 #2
I'd like to be able to look at the exception that was caught.
This would be immensely useful, for instance, in some sort of exception
handler one might have in main(), for instance.

Alf P. Steinbach wrote:
* jo*********@gmail.com:
Is there anyway that I can get at the actual exception in a catch(...)?

throw

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 6 '06 #3
Don't

* jo*********@gmail.com:
I'd like to be able to look at the exception that was caught.
This would be immensely useful, for instance, in some sort of exception
handler one might have in main(), for instance.

Alf P. Steinbach wrote:
>* jo*********@gmail.com:
>>Is there anyway that I can get at the actual exception in a catch(...)?
throw
top-post or middle-post.
>>
--
A: Because it messes up the order in which people normally read text.
What part
>Q: Why is it such a bad thing?
A: Top-posting.
of the answer

>Q: What is the most annoying thing on usenet and in e-mail?
was it you didn't understand?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 6 '06 #4

Alf P. Steinbach wrote:
Don't

* jo*********@gmail.com:
I'd like to be able to look at the exception that was caught.
This would be immensely useful, for instance, in some sort of exception
handler one might have in main(), for instance.

Alf P. Steinbach wrote:
* jo*********@gmail.com:
Is there anyway that I can get at the actual exception in a catch(...)?
throw

top-post or middle-post.
>
--
A: Because it messes up the order in which people normally read text.

What part
Q: Why is it such a bad thing?
A: Top-posting.

of the answer

Q: What is the most annoying thing on usenet and in e-mail?

was it you didn't understand?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Forgive me. I agree that top-posting is bad. Unfortunately most of the
world does it. Good luck with changing that.
Are you saying that since it is possible to throw nothing, the idea of
of getting at the exception caught by a default handler is foolish?
Help me in my ignorance.

Dec 6 '06 #5
Hi

jo*********@gmail.com wrote:
I'd like to be able to look at the exception that was caught.
This would be immensely useful, for instance, in some sort of exception
handler one might have in main(), for instance.
And how would you do that? What kind of inspection would you want to do? You
don't know the type of what has been thrown. It could be a double. Or a
member pointer. Or an object of type X...

Markus

Dec 6 '06 #6
Hi

jo*********@gmail.com wrote:
Are you saying that since it is possible to throw nothing, the idea of
of getting at the exception caught by a default handler is foolish?
Help me in my ignorance.
No, he is saying that there is only one thing you can do with the exception
caught in a catch-all handler, which is re-throwing the exception. This is
what
throw;
does. You cannot throw "nothing".

Markus

Dec 6 '06 #7
josephga...@gmail.com wrote:
Forgive me. I agree that top-posting is bad. Unfortunately most of the
world does it. Good luck with changing that.
All Alf is getting at is that you should do as the Romans do when in
Rome (cf.
http://www.parashift.com/c++-faq-lit....html#faq-5.4).
Are you saying that since it is possible to throw nothing, the idea of
of getting at the exception caught by a default handler is foolish?
Help me in my ignorance.
No, he's saying you can rethrow the exception by using "throw;" and
then catch the desired exceptions or class of exceptions (e.g.,
something in the std::exception hierarchy).

Cheers! --M

Dec 6 '06 #8
* jo*********@gmail.com:
>
Forgive me. I agree that top-posting is bad. Unfortunately most of the
world does it.
Not hereabouts.

And please don't quote signatures either.

:-)

Good luck with changing that.
No need, we only need to inform the newbies.

See FAQ item 5.2 or thereabouts (I forget the number).

It's nearly always a good idea to read the FAQ before posting.

Are you saying that since it is possible to throw nothing, the idea of
of getting at the exception caught by a default handler is foolish?
No.

Because it's impossible to throw nothing, it's very easy to get at the
exception.

IOW., what do you think "throw;" throws?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 6 '06 #9

Markus Moll wrote:
Hi

jo*********@gmail.com wrote:
I'd like to be able to look at the exception that was caught.
This would be immensely useful, for instance, in some sort of exception
handler one might have in main(), for instance.

And how would you do that? What kind of inspection would you want to do? You
don't know the type of what has been thrown. It could be a double. Or a
member pointer. Or an object of type X...

Markus
Obviously C++ has no base exception class like .net or java....

Dec 6 '06 #10

Alf P. Steinbach wrote:
* jo*********@gmail.com:

Forgive me. I agree that top-posting is bad. Unfortunately most of the
world does it.

Not hereabouts.

And please don't quote signatures either.

:-)

Good luck with changing that.

No need, we only need to inform the newbies.

See FAQ item 5.2 or thereabouts (I forget the number).

It's nearly always a good idea to read the FAQ before posting.

Are you saying that since it is possible to throw nothing, the idea of
of getting at the exception caught by a default handler is foolish?

No.

Because it's impossible to throw nothing, it's very easy to get at the
exception.

IOW., what do you think "throw;" throws?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
What does throw throw?

Dec 6 '06 #11
Hi

jo*********@gmail.com wrote:
Markus Moll wrote:
>And how would you do that? What kind of inspection would you want to do?
You don't know the type of what has been thrown. It could be a double. Or
a member pointer. Or an object of type X...

Obviously C++ has no base exception class like .net or java....
Well, there is the std::exception hierarchy, but you are not forced to use
it, no.
On the other hand, nobody stops you from throwing only objects of classes
from some exception hierarchy (which may or may not be related to
std::exception), so that you can catch all of those exceptions (and still
do something with them).

Markus

Dec 6 '06 #12
jo*********@gmail.com wrote:
Is there anyway that I can get at the actual exception in a catch(...)?
You always need to know the possible exception types in advance. But you
can re-throw a caught exception in order to unify handling:

void CatchHandler()
{
try
{
throw; // rethrows the exception
}
catch( CThisException& e ) // need to know these types up front
{
// handle
}
catch( CThatException& e )
{
// handle
}
// etc.
}
int main()
{
try
{
// do stuff
}
catch(...)
{
CatchHandler();
}

// do stuff

try
{
// do stuff
}
catch(...)
{
CatchHandler();
}
}
Dec 6 '06 #13

Eberhard Schefold wrote:
jo*********@gmail.com wrote:
Is there anyway that I can get at the actual exception in a catch(...)?

You always need to know the possible exception types in advance. But you
can re-throw a caught exception in order to unify handling:

void CatchHandler()
{
try
{
throw; // rethrows the exception
}
catch( CThisException& e ) // need to know these types up front
{
// handle
}
catch( CThatException& e )
{
// handle
}
// etc.
}
int main()
{
try
{
// do stuff
}
catch(...)
{
CatchHandler();
}

// do stuff

try
{
// do stuff
}
catch(...)
{
CatchHandler();
}
}
That's an immensely useful concept.
BTW
http://publib.boulder.ibm.com/infoce...c05cplr203.htm

Dec 6 '06 #14
Alf P. Steinbach wrote:
* jo*********@gmail.com:

Forgive me. I agree that top-posting is bad. Unfortunately most of
the world does it.

Not hereabouts.

And please don't quote signatures either.

:-)

Good luck with changing that.

No need, we only need to inform the newbies.

See FAQ item 5.2 or thereabouts (I forget the number).
5.4. It's a good idea to read all the 5.* entries:

<http://www.parashift.com/c++-faq-lite/how-to-post.html>


Brian
Dec 6 '06 #15

jo*********@gmail.com wrote:
I'd like to be able to look at the exception that was caught.
This would be immensely useful, for instance, in some sort of exception
handler one might have in main(), for instance.
Surely you must know what type of exceptions your code might possibly
throw and you can create catch blocks to catch specifically those
types. Also you can have a catch handler for std::exception which
should cover exceptions from the language and from standard containers.
What is the reason you don't know which exceptions you might throw? Is
it because you don't know your own codebase well enough? Or are using
undocumented binary components?

--
Ivan
http://www.0x4849.net

Dec 7 '06 #16

Ivan Novick wrote:
jo*********@gmail.com wrote:
I'd like to be able to look at the exception that was caught.
This would be immensely useful, for instance, in some sort of exception
handler one might have in main(), for instance.

Surely you must know what type of exceptions your code might possibly
throw and you can create catch blocks to catch specifically those
types. Also you can have a catch handler for std::exception which
should cover exceptions from the language and from standard containers.
What is the reason you don't know which exceptions you might throw? Is
it because you don't know your own codebase well enough? Or are using
undocumented binary components?

--
Ivan
http://www.0x4849.net
Both. I'm trying to fix up a really screwed up project.

Dec 7 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Zork | last post by:
Hi, I am trying to stop object creation (in this case ill use a ball as the object) via use of exceptions. In essence, if the ball does not have an owner, I do not want the ball object created....
7
by: Ekim | last post by:
hy, I've a question concerning exception-handling in c++: is there a possibility to catch any exception (I know one can do that by "catch(...)") and display its default-error-message (like in...
5
by: Miyra | last post by:
Hi. I'm working with an app that uses exceptions for control flow. These are code blocks where exceptions are thrown/caught regularly. A couple hundred exceptions occur per hour and they're caught...
0
by: ALI-R | last post by:
I am using the code below to open Outlook as user clicks on "Email this page" try { string subjectEmail=string.Format("Magnet Alert Center - Alerts for : {0}",Request.QueryString);
3
by: Chris Baldwin | last post by:
Hello, I'm having a problem with a mixed managed/unmanaged DLL. When I attempt to reference "Exception" in my VB.NET code, it conflicts with some other "exception" that gets somehow gets into...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
4
by: cj | last post by:
my old code Try Dim sw As New System.io.StreamWriter(fileName, True) sw.WriteLine(strToWrite) sw.Close() Catch End Try my new code
0
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.