assert unittest doesn't respect assertThrown

Ali Çehreli acehreli at yahoo.com
Wed Jan 21 22:40:39 UTC 2026


On 1/20/26 3:04 PM, Brother Bill wrote:

 > Just curious as to why the unittest failed.  After all, the assert was
 > thrown.

I don't think there was an issue there.

 > Is it because the try - catch block has an assert, but the catch block
 > didn't catch it

Yes. Your catch was for Exception but the exception type thrown by 
assert is not under the Exception hierarchy (it is an Error, not Exception).

 > which crashed the program before the unittest completed?

unittest blocks are executed before 'main' is entered. So, unittest 
blocks worked correctly but the program terminated with an uncaught 
exception.

Ali



More information about the Digitalmars-d-learn mailing list