www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Thoughts about exception reporting

reply pineapple <meapineapple gmail.com> writes:
Something I keep going back and forth on is the best way to 
handle exception reporting in different contexts. There are so 
many idioms to use here and none of them feel quite ideal. I'm 
not sure the best way to improve it, but I'm hoping a discussion 
might produce some useful ideas.

Some suggestions, apart from the obvious "exceptions shouldn't 
require the gc":

- nothrow might be repurposed to mean "doesn't throw recoverable 
exceptions", and it not forbid throwing objects that inherit from 
Error. It's limiting to have to use asserts to report 
nonrecoverable errors in nothrow code, rather than specialized 
error classes that might provide better information as to what 
went wrong.

- pure might no longer prevent code from throwing `static const` 
objects, so that error reporting can still be done using  nogc 
and user-defined error classes in pure functions. It's 
unintuitive that asserts and `throw new WhateverError` should be 
allowed, but not `static const error = new WhateverError; throw 
error`.
Feb 03 2017
parent Chris Wright <dhasenan gmail.com> writes:
On Fri, 03 Feb 2017 19:50:19 +0000, pineapple wrote:
 - nothrow might be repurposed to mean "doesn't throw recoverable
 exceptions", and it not forbid throwing objects that inherit from Error.
That's what it means today: void foo() nothrow { throw new Error("Ohai!"); }
Feb 03 2017