Re: Exception Handling in Release Mode
Ulrich Eckhardt wrote:
Moahn wrote:
int i = 0;
try
{
int m = 17/i;
This will not throw a C++ exception.
This may throw a C++ exception. It's undefined behavior: it may
also cause a core dump (the preferred behavior), or set m to
INT_MAX, or... reformat your hard disk. Which one it does may
also depend on the time of day, the phases of the moon,
or---apparently the case for the original poster---the options
passed to the compiler.
}
catch(...)
{[...]}
Note: some compilers allow catching several things that are not C++
exceptions with such an exception handler.
I'm not sure what you mean by a "C++" exception. C++ allows
anything to be used as an exception; I regularly throw int's
(rather than call exit()), and in quicky tests, I'll throw a
char const*. If by C++ exception, you mean a standard
exception, every compiler I know will catch other things here;
the standard requires it.
When and why they do that is up
to the particular platform, the C++ language doesn't give you an answer
there. I'd suggest asking the question in microsoft.public.vc.language.
Other than that, try this:
try {
throw std::runtime_error("test");
} catch( std::exception const& e) {
std::cout << "exception '" << e.what() << "'" << std::endl;
}
BTW: VC6 is almost obsolete and non-standard in several aspects. Consider
upgrading or, if that is too expensive, sidegrading to DevC++.
I don't know if it's considered an upgrade, but Visual Studios
2005 is available free; it's also a pretty good compiler.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientie objet/
Beratung in objektorientierter Datenverarbeitung
9 place Simard, 78210 St.-Cyr-l'Icole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]