www.digitalmars.com         C & C++   DMDScript  

c++.command-line - Exception handling problem - bug?

I have following simple code:

==== except.cpp ===============================

#include <cstdio>
#include <eh.h>

class Exception {

void CheckFunc( void )
try {
throw new Exception;
catch ( Exception * const exception ) {
delete exception;
fprintf( stdout, "Exception caught successfully. (%s:%u)\n",
__FILE__, __LINE__ );
catch ( ... ) {
fprintf( stderr, "Weird exception caught! (%s:%u)\n",
__FILE__, __LINE__ );

void UncaughtHandler( void )
fprintf( stderr, "Uncaught (unexpected) exception handler reached." );

int main( int argc, char ** argv )
set_terminate( UncaughtHandler );
set_unexpected( UncaughtHandler );
return 0;

/* EOF */

it compiles fine (I use -Ae dmc flag), but in try block in the CheckFunc()
function the Exception * is not caught in the catch() block (and even weird
exception is not caught in the catch( ... ) block) and the control is passed to
UncaughtHandler(). But I feel the exception should be caught in the catch (
Exception * ) block, or em I wrong?

And furthermore, if I declare the CheckFunc() function without the throw()
clause (meaning CheckFunc() can throw any exception) the Exception is then
caught in the catch block as I expect.

But I think I should declare the function using throw() (throws nothing) if I
catch all (even weird here, but not neccessarily) exceptions which may be
thrown; but it seems, if I declare the function using throw(), the exception
handling is not processed at all in that function by the dmc compiler. Other
compilers (msvc, OpenWatcom, gcc, bcc32) process this sample as I expect (=
catch the exception and do not pass it to uncaught exception handler).
(I use 32-bit dmc on Windows)
May 05 2005