www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - BUG: finally block executes multiple times

reply Sean Kelly <sean f4.ca> writes:
Executing the following code:

void main()
{
try
{
try
{
printf( "hello\n" );
throw new Exception( "first" );
}
finally
{
printf( "finally\n" );
throw new Exception( "second" );
}
}
catch( Exception e )
{
printf( "catch\n" );
e.print();
}
}

prints:

hello
finally
finally
.. (maybe 100 iterations)
finally
Nov 16 2004
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
This version of the problem seems to be Windows-only. On Linux I get:




error.html reads:




Due to "catch( Exception e )" I would expect the output:





Sean Kelly schrieb am Tue, 16 Nov 2004 20:23:32 +0000 (UTC):
 Executing the following code:

 void main() {
	try{
		try{
			printf( "hello\n" );
			throw new Exception( "first" );
		}finally{
			printf( "finally\n" );
			throw new Exception( "second" );
 		}
 	} catch( Exception e ) {
		printf( "catch\n" );
		e.print();
 	}
 }

 prints:

 hello
 finally
 finally
 .. (maybe 100 iterations)
 finally
Added to DStress as: http://svn.kuehne.cn/dstress/run/finally_01.d Thomas
Nov 17 2004
parent Sean Kelly <sean f4.ca> writes:
In article <tgjr62-2vv.ln1 kuehne.cn>, Thomas Kuehne says...
This version of the problem seems to be Windows-only. On Linux I get:




error.html reads:




Due to "catch( Exception e )" I would expect the output:




I was looking at the code for this yesterday and current behavior is to find the exception handler for the original exception and then to evaluate all the "finally" blocks that were passed. So I suppose it makes sense that if one of these blocks throws an excecption it would be handled higher up in the program. I've posted a message in the main thread asking about what the correct behavior for this *should* be, as I'm not convinced either is correct. Still, the Windows bug should be fixed. Sean
Nov 17 2004