www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DMD special exception "catch not allowed in finally block"

reply Bradley Smith <digitalmars-com baysmith.com> writes:
Why does DMD have this special exception for the finally block?

The documentation states that "A FinallyStatement may not exit with a 
throw, goto, break, continue, or return; nor may it be entered with a 
goto.", but this is obviously not the case in the following code. The 
closeResources() method throws an exception which exits the finally 
statement. DMD simply is not allowing code which would handle the exception.

void closeResources() {
	throw new Exception("from throwsException");
}

void main() {
	// open resources
	try {
		// use resources
		
	} catch(Exception e) {
		// handle exception
		
	} finally {
		closeResources();
	}
}


If this exception is really a part of the language, shouldn't the gdc 
compiler give the same behavior? The following code compiles with gdc 
but not dmd.

void closeResources() {
	throw new Exception("from throwsException");
}

void main() {
	// open resources
	try {
		// use resources
		
	} catch(Exception e) {
		// handle exception
		
	} finally {
		try {
			closeResources();
		} catch (Exception e) {
		}
	}
}


Thanks,
   Bradley
Jun 23 2006
parent Hasan Aljudy <hasan.aljudy gmail.com> writes:
Bradley Smith wrote:
 
 If this exception is really a part of the language, shouldn't the gdc 
 compiler give the same behavior? The following code compiles with gdc 
 but not dmd.
a bit OT, but, gdc is not a standard/reference compiler .. dmd is.
Jun 25 2006