On Monday, 21 February 2022 at 11:21:52 UTC, Mike Parker wrote:
On Monday, 21 February 2022 at 11:07:55 UTC, Basile B. wrote:
[...]

This has nothing to do with which exceptions types a function throws. The compiler doesn't dig into that. You have to catch `Exception`.

```D
import std.stdio;

class MyException : Exception {
    this(string msg) { super(msg); }
}

void throwing(int x) {
    if(x > 2) throw new MyException("Derp!");
    else writeln(x);
}

void noThrowing() nothrow {
    try {
        throwing(10);
    }
    catch(MyException me) {}
}

void main()
{
    noThrowing();
}
```

```
onlineapp.d(14): Error: function `onlineapp.throwing` is not `nothrow` onlineapp.d(12): Error: `nothrow` function `onlineapp.noThrowing` may throw
```

Thank You for detailed explanation.

Reply via email to