Console application termination following exception thrown in constructor (VS 2005)
- From: "Paul" <vhr@xxxxxxxxxxxxxxxxx>
- Date: Mon, 15 Jan 2007 10:16:48 -0000
The code looks like the following:
-----------------------
C::C(const char* ss...)
try
: ..., settings(ss) /*third-party class that can throw E*/, ...
{
...
}
catch (const E& e) {
std::cerr << e.what();
}
;
-----------------------
(First, a minor point: in my experience whenever constructs similar to above
are used - when "try" appears outside the main function body not necessarily
within a constructor (can be something along these lines: int main() try
{...} catch (...) {...}) - unless they are fairly simple, code will not
compile without the semicolon (;) after the closing curly brace.)
I understand that when a constructor of a class throws an exception, that
class will not be constructed even if the exception is caught as in the
above code - and I do not count on the object creation. However, I could not
find a way to exit the application gracefully in this case. The above works
to the extent that the error (exception) is reported properly but this is
followed by
-----------------------
This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
-----------------------
and then the dialogue box "Please tell Microsoft about this problem."
appears.
When the object construction is put within a try-block
try { C c(...); } catch (...) { std::cerr << "Error.\n"; }
the application just silently exits.
Is there a way to display just the error message when "settings(ss)" throws
an exception without the "This application has requested..."? (I am aware of
how to disable "Please tell Microsoft..." for an application via an API but
it is "The application has requested..." that I do not know how to deal
with.)
Thank you.
Paul
.
- Follow-Ups:
- RE: Console application termination following exception thrown in constructor (VS 2005)
- From: Charles Wang[MSFT]
- Re: Console application termination following exception thrown in constructor (VS 2005)
- From: Tom Widmer [VC++ MVP]
- Re: Console application termination following exception thrown in constructor (VS 2005)
- From: Ulrich Eckhardt
- RE: Console application termination following exception thrown in constructor (VS 2005)
- Prev by Date: Resource Editor: Export Dimmed
- Next by Date: Re: Resource Editor: Export Dimmed
- Previous by thread: Resource Editor: Export Dimmed
- Next by thread: Re: Console application termination following exception thrown in constructor (VS 2005)
- Index(es):
Relevant Pages
|