Are exceptions caught in unittests?
Ferhat Kurtulmuş
aferust at gmail.com
Fri Feb 16 08:06:26 UTC 2024
On Friday, 16 February 2024 at 07:43:24 UTC, Ferhat Kurtulmuş
wrote:
> When I tried to catch exceptions in my unit test, I found that
> exceptions were not thrown or caught in the unit test blocks.
> So, I cannot use assertThrown at all. Is this a bug or expected
> behavior that I don't know?
>
> Using LDC 1.36.0 on Windows.
>
> https://github.com/aferust/evalex/blob/main/source/evalex.d#L694
Even a test code like this does not work:
```d
string division(int a, int b) {
string result = "";
try {
if( b == 0 ) {
throw new Exception("Cannot divide by zero!");
} else {
result = format("%s",a/b);
}
} catch (Exception e) {
result = e.msg;
}
return result;
}
assertThrown({division(50, 0);});
```
More information about the Digitalmars-d-learn
mailing list