Rethrow an exception like in C++?

Jonathan M Davis jmdavisProg at gmx.com
Fri Mar 8 12:32:12 PST 2013


On Friday, March 08, 2013 20:16:13 Rob T wrote:
> If you know of a better way to implement an exception handler in
> D, then I'd like to know about it. For example I do know that D's
> system allows you to insert callback functions, but I don't yet
> know how to make use out of it, so perhaps there's a better way.

If all you need to do is do something when an exception is thrown and don't 
need the exception itself, then just use scope statements:

http://dlang.org/statement.html#ScopeGuardStatement

scope(failure) doSomethingOnException();
//code that might throw

The block inside the scope statement will run when the surrounding scope is 
exited with an exception. That _really_ cleans up a lot of code that just 
wants to react to the fact that an exception was thrown and not actually do 
anything with it.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list