Console application termination following exception thrown in constructor (VS 2005)



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


.



Relevant Pages

  • Re: DbC & Exceptions & Style
    ... exception. ... Different ways the constructor can fail ... to avoid writing code that converts GUI data into objects, ... All domain objects must now provide a default constructor. ...
    (comp.object)
  • Re: Controlled types and exception safety
    ... >> propagate an exception. ... >> For an Adjust invoked as part of an assignment operation, ... But a user-defined constructor is ... a user-defined constructor has just turned on the ...
    (comp.lang.ada)
  • Re: is such exception handling approach good?
    ... There is nothing wrong with throwing from constructor. ... It may be a good design, it may not be a good design from user's point ... resource API to free-up the resource on exception. ... change something - that is not initialization. ...
    (microsoft.public.vc.language)
  • Re: Question concerning object-oriented programming
    ... constructor the inspectof the state fails to verify key ... Better yet the constructor could throw an exception. ... opposed to stateless) object can know if it is in an invalid state. ...
    (comp.programming)
  • Re: Why does std::exception constructor specifies it can throw any ?
    ... > specifies that the constructors could throw any exception becuase they ... The constructor, copy constructor, operator=, ... DerivedException() throw ... contained objects don't throw. ...
    (comp.lang.cpp)