Why writeln can't be converted to nothrow with just catching of StdioException
bauss
jj_1337 at live.dk
Mon Feb 21 13:17:17 UTC 2022
On Monday, 21 February 2022 at 10:57:07 UTC, Basile B. wrote:
> On Monday, 21 February 2022 at 10:53:56 UTC, Basile B. wrote:
>> On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote:
>>> Do I completely not understand what is `nothrow` or why I
>>> can't make function nothrow with just catching StdioException?
>>>
>>> This doesn't work
>>> ```d
>>> nothrow void hello() {
>>> try {
>>> writeln("Hello, World!")
>>> } catch (StdioException) {}
>>> }
>>> ```
>>> This doest work
>>> ```d
>>> nothrow void hello() {
>>> try {
>>> writeln("Hello, World!")
>>> } catch (Exception) {}
>>> }
>>> ```
>>
>> I believe it's because it can throw ConvException as well ;)
>
> However you're totally right to open a discussion, the
> documentation is innacurate:
>
> in https://dlang.org/phobos/std_stdio.html#.writeln
>
> just StdioException is mentioned ;)
What if we could do ex. this:
```d
__traits(possibleExceptions, writeln);
```
Which would give all exceptions a function could possibly throw.
That way we could build our try/catch based on that.
For nothrow it should return nothing of course, for extern
functions that have no source code available it should only
return "Exception" of course.
Just a thought I just had.
More information about the Digitalmars-d-learn
mailing list