digitalmars.D.learn - Can I assert in nothrow functions ?
- ponce (10/10) Oct 01 2011 Question 1:
- Timon Gehr (8/17) Oct 01 2011 nothrow means that a function won't throw an exception. They can still
- bearophile (4/7) Oct 01 2011 nothrow also allows some better optimization of the code.
- ponce (2/2) Oct 02 2011 Thanks Timon and Bearophile for answers.
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. Question 2: When to use nothrow? - Where one can be sure the code won't throw? - Where we want the compiler to check the function and callees for unwanted throwing? Thanks.
Oct 01 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.
Oct 01 2011
Timon Gehr: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.nothrow also allows some better optimization of the code. Bye, bearophile
Oct 01 2011
Thanks Timon and Bearophile for answers. I realize nothrow is way more useful than I first thought.
Oct 02 2011