Re: catch (...)
From: Cy Edmunds (cedmunds_at_spamless.rochester.rr.com)
Date: 01/14/04
- Next message: Daniel T.: "Re: Looking for good naming convention for class attributes"
- Previous message: Jack Klein: "Re: MSVC++ Question"
- In reply to: Tom Groszko: "catch (...)"
- Next in thread: Nick Hounsome: "Re: catch (...)"
- Reply: Nick Hounsome: "Re: catch (...)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 14 Jan 2004 03:07:44 GMT
"Tom Groszko" <newscorrespondent@charter.net> wrote in message
news:400457e2_1@Usenet.com...
> Given a try catch scenario
>
> try
> { dosomething();
> }
> catch (...)
> { report some error
> }
>
> Is there any way to figure out what exception is being thrown and
> represented by the ellipsis in the above code?
> I am using MS C++ if that environment has something different.
>
> I am catching an error and sure would like to know what is wrong. I have
> tried to catch everything in the docs for the library and none of those
are
> the error.
>
> Thanks
> Tom G.
[snip]
You could try this:
try
{
dosomething();
}
catch (std::exception &e)
{
std::cerr << "std::exception " << typeid(e).name() << '\n';
std::cerr << e.what() << '\n';
}
catch (...)
{
std::cerr << "non-standard exception\n";
}
If you don't know where the error is coming from but whoever threw it was
nice enough to base his exception class on std::exception you should be able
to get some information possibly including the actual type name and perhaps
an error message. OK, so that would be lucky. But if you were getting an
exception from MY code it would work. :)
catch(...) should be a last resort because once you are there you never know
what to do.
-- Cy http://home.rochester.rr.com/cyhome/ PS depending on your compiler you might have to do something specific to turn on RTTI.
- Next message: Daniel T.: "Re: Looking for good naming convention for class attributes"
- Previous message: Jack Klein: "Re: MSVC++ Question"
- In reply to: Tom Groszko: "catch (...)"
- Next in thread: Nick Hounsome: "Re: catch (...)"
- Reply: Nick Hounsome: "Re: catch (...)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|