Jump to page: 1 2
Thread overview
Why writeln can't be converted to nothrow with just catching of StdioException
Feb 21, 2022
partypooper
Feb 21, 2022
Basile B.
Feb 21, 2022
Basile B.
Feb 21, 2022
bauss
Feb 21, 2022
Basile B.
Feb 21, 2022
partypooper
Feb 21, 2022
Basile B.
Feb 21, 2022
partypooper
Feb 21, 2022
Basile B.
Feb 21, 2022
Mike Parker
Feb 21, 2022
partypooper
Feb 21, 2022
Basile B.
Feb 21, 2022
Mike Parker
Feb 21, 2022
partypooper
Feb 21, 2022
Mike Parker
February 21, 2022

Do I completely not understand what is nothrow or why I can't make function nothrow with just catching StdioException?

This doesn't work

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (StdioException) {}
}

This doest work

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (Exception) {}
}
February 21, 2022

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

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (StdioException) {}
}

This doest work

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (Exception) {}
}

I believe it's because it can throw ConvException as well ;)

February 21, 2022

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

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (StdioException) {}
}

This doest work

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 ;)

February 21, 2022

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

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (StdioException) {}
}

This doest work

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (Exception) {}
}

I believe it's because it can throw ConvException as well ;)

more likely UTFException actually

February 21, 2022

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

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (StdioException) {}
}

This doest work

nothrow void hello() {
  try {
    writeln("Hello, World!")
  } catch (Exception) {}
}

https://issues.dlang.org/show_bug.cgi?id=22800

February 21, 2022

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?

D does not have checked exceptions like Java, so the compiler doesn't have anyway to verify that any function you call won't throw a given exception. You have to catch Exception to satisfy the nothrow requirement.

February 21, 2022

On Monday, 21 February 2022 at 10:58:26 UTC, Basile B. wrote:

>

more likely UTFException actually

Additionaly catching UTF and Conv exceptions doesn't help.

February 21, 2022

On Monday, 21 February 2022 at 11:05:42 UTC, partypooper wrote:

>

On Monday, 21 February 2022 at 10:58:26 UTC, Basile B. wrote:

>

more likely UTFException actually

Additionaly catching UTF and Conv exceptions doesn't help.

Yeah there must be another one then. Something actionnable is the documentation.

February 21, 2022

On Monday, 21 February 2022 at 11:04:46 UTC, Mike Parker 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?

D does not have checked exceptions like Java, so the compiler doesn't have anyway to verify that any function you call won't throw a given exception. You have to catch Exception to satisfy the nothrow requirement.

Oh, that's explain it.
So with such behavior there is no reason at all to make make function nothrow, if it uses throw functions in its body? And as much as I already know compliler can deduce and automatically adds nothrow to all functions which do not throw exceptions. Right?

February 21, 2022

On Monday, 21 February 2022 at 11:07:55 UTC, Basile B. wrote:

>

Yeah there must be another one then. Something actionnable is the documentation.

What about Mike Parker answer?

« First   ‹ Prev
1 2