digitalmars.D.learn - How the heck is onInvalidMemoryOperationError() nothrow?
- Jeremy DeHaan (4/4) May 05 2016 In core.exception, we have a lovely function called
- tsbockman (12/17) May 05 2016 From the spec
- Jeremy DeHaan (2/15) May 06 2016 Oh, interesting. That makes sense, thanks.
In core.exception, we have a lovely function called onInvalidMemoryOperationError(). This function is marked as nothrow (plus other annotations). This function literally does nothing except throwing an error. How can it be marked as nothrow?
May 05 2016
On Friday, 6 May 2016 at 02:57:59 UTC, Jeremy DeHaan wrote:In core.exception, we have a lovely function called onInvalidMemoryOperationError(). This function is marked as nothrow (plus other annotations). This function literally does nothing except throwing an error. How can it be marked as nothrow?From the spec (https://dlang.org/spec/function.html#nothrow-functions): "Nothrow functions can only throw exceptions derived from class Error." Throwing an Error is, for many purposes, considered fundamentally different than throwing an Exception because Error objects aren't meant to be caught by user code. Throwing an Error is supposed to just be a way of crashing the program with a nice message and stack trace. A key benefit of this distinction, is that it enables the use of `assert()` statements in `nothrow` code.
May 05 2016
On Friday, 6 May 2016 at 03:24:23 UTC, tsbockman wrote:On Friday, 6 May 2016 at 02:57:59 UTC, Jeremy DeHaan wrote:Oh, interesting. That makes sense, thanks.[...]From the spec (https://dlang.org/spec/function.html#nothrow-functions): "Nothrow functions can only throw exceptions derived from class Error." Throwing an Error is, for many purposes, considered fundamentally different than throwing an Exception because Error objects aren't meant to be caught by user code. Throwing an Error is supposed to just be a way of crashing the program with a nice message and stack trace. A key benefit of this distinction, is that it enables the use of `assert()` statements in `nothrow` code.
May 06 2016