Comment #0 by pro.mathias.lang — 2020-01-15T13:43:24Z
Code:
```
void main () @safe @nogc nothrow
{
scope exc = new Exception("Baguette");
try {
throw exc;
} catch (Exception e) {
assert(e is exc);
}
}
```
Result:
bug.d(5): Error: scope variable exc may not be thrown
The code is obviously `@safe`: While a scope variable is thrown, the function itself is nothrow, meaning the function cannot escape the scope of this function (even if passed down to another function).
Comment #1 by dkorpel — 2021-07-11T23:43:47Z
It's not that obvious, checking nothrow is not enough. This is not allowed:
```
void main () @safe @nogc nothrow
{
try {
scope exc = new Exception("Baguette");
throw exc;
} catch (Exception e) {
assert(e is exc);
}
}
```
There needs to be a check whether the try-catch block that catches the exception is inside the scope of the variable that is being thrown.
Comment #2 by robert.schadek — 2024-12-13T19:06:50Z