Catch block not hit in unittest

Lucia Cojocaru via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 24 04:04:33 PST 2016


Hello,

I am trying to assert the fact that a UnicodeException is thrown 
by the piece of code added in this PR:
https://github.com/dlang/druntime/pull/1696/files

The unittest is in druntime/src/rt/lifetime.d:

unittest
{
     import core.exception : UnicodeException;

     try
     {
         string ret;
         int i = -1;
         ret ~= i;
     }
     catch(UnicodeException e)
     {
         assert(e.msg == "Invalid UTF-8 sequence");
     }
}

However running the tests for druntime fails because the 
exception is not caught:
****** FAIL release64 rt.lifetime
core.exception.UnicodeException at src/rt/lifetime.d(2031): Invalid 
UTF-8 sequence

I tried to use the same code as in the unittest above in a 
regular D source file and the UnicodeException was properly 
caught there.

Do you know what the problem might be?

Thank you,
Lucia



More information about the Digitalmars-d-learn mailing list