Can I assert in nothrow functions ?
Timon Gehr
timon.gehr at gmx.ch
Sat Oct 1 10:25:06 PDT 2011
On 10/01/2011 07:07 PM, ponce wrote:
> Question 1:
>
> assert can throw an AssertError in debug mode.
> What happens when I mark as nothrow a function with assertions ?
> The compiler accept it but I have a bad feeling about it.
nothrow means that a function won't throw an exception. They can still
throw errors. (errors are not supposed to be caught)
>
> Question 2:
>
> When to use nothrow?
> - Where one can be sure the code won't throw?
... won't throw an exception.
> - Where we want the compiler to check the function and callees for
> unwanted throwing?
... throwing an exception.
nothrow is part of the function interface. You should mark your
functions with nothrow when you want to explicitly guarantee to the
clients of your function that it won't throw an exception.
More information about the Digitalmars-d-learn
mailing list