On Thursday, 14 January 2016 at 02:16:40 UTC, userABCabc123 wrote:
On Wednesday, 13 January 2016 at 19:05:30 UTC, Josh Phillips wrote:
Oh wow that's easy. They should really make that more clear in the dlang reference. They way it sounds there made me think that if a function doesn't throw any errors it automatically is 'nothrow'

No, because actually you can have a function that uses sub-functions that throw, but marked explicitly nothrow, because it hides the stuff under the carpet.

---
void bar()
{
    throw new Exception("kaboom");
}

void foo() nothrow
{
  try {bar;}
  catch {/*under the carpet*/}
}
---

and that will compile.

Ok? I'm not sure what you are saying no to and I understand this. It makes sense because foo catches bar's error and doesn't throw it up and further. I was just saying that the reference here https://dlang.org/spec/function.html was not all that clear since the section entitled nothrow merely states:

"Nothrow functions do not throw any exceptions derived from class Exception.
Nothrow functions are covariant with throwing ones."

A deeper search on the page made me realize that there are more examples later which clarify how to declare a "nothrow" function however I didn't bother looking deeper at the time since the main section for nothrows gave no indication that I should.

Reply via email to