How to handle try-catch blocks, nothrow and logfiles

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 24 22:54:55 PDT 2014


On Saturday, 24 May 2014 at 17:09:24 UTC, Tim wrote:
> But doing this in all my methods

You shouldn't do it in all methods, only top-level ones, because 
they are called from 3rd party code, which will do whatever 
things with the exceptions from nothing to terminating the 
application. Already mentioned defensive trick is to log 
exception in its constructor, so that there's no way to mute it. 
If you log exceptions in all methods, the log quickly becomes 
messy.

> void handleExceptions(Exception e)
> {
>    // Write to log file
> }
>
> void myMethod() throwTo(handleExceptions)
> {
>    // Call something that probably throws an exception
> }

If you need only Exception as a parameter for logger, leave it 
that way, what do you want to change in that interface?


More information about the Digitalmars-d-learn mailing list