The Right Approach to Exceptions

Martin Nowak dawg at dawgfoto.de
Sat Feb 18 11:12:43 PST 2012


On Sat, 18 Feb 2012 19:52:05 +0100, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> There's a discussion that started in a pull request:
>
> https://github.com/alexrp/phobos/commit/4b87dcf39efeb4ddafe8fe99a0ef9a529c0dcaca
>
> Let's come up with a good doctrine for exception defining and handling  
> in Phobos. From experience I humbly submit that catching by type is most  
> of the time useless.
>
>
> Andrei

Exception are useful for handling unknown errors and probably to bundle
error handling at a bigger scope.
You don't want to use specific exceptions because it couples unrelated  
code.
The distinction of recoverable Exceptions and non-recoverable Errors is  
good enough
in most cases.

Typed exception being used for local error recovery is about the same as  
using
error codes but at a bigger expense. On the plus side exception can carry  
more
specific error messages, which could be solved for error codes too.


More information about the Digitalmars-d mailing list