Why writeln can't be converted to nothrow with just catching of StdioException
partypooper
pythonproof at gmail.com
Mon Feb 21 13:10:15 UTC 2022
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.
More information about the Digitalmars-d-learn
mailing list