How to handle try-catch blocks, nothrow and logfiles

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 24 13:41:32 PDT 2014


On Saturday, 24 May 2014 at 17:09:24 UTC, Tim wrote:
> Imagine I've an application where I want log all thrown 
> exceptions.

Arguably, that's not something you'd want to do. In a "normal" 
application, exceptions get thrown around, and it is completely 
normal. In particular, the *thrower* has no way to know its 
context, and whether or not the situation it has encountered is 
"catastrophic exception" or "completely normal". Only the 
"catcher" can know.

>    2) When I want create an application where all methods are 
> defined as >nothrow< - how can I realize that? Writing to a 
> log-file is already throwable. Yes, I can catch the exception 
> and write the same to the command line but that's also 
> unsafe... are there any nothrow-function to write a file or 
> something to the command line? It's a bit sad when I want log 
> an exception and I'm unable to write the log entry because 
> something happened. So how can make sure that I log all 
> exceptions? Is that even possible?

Well, you seem to be mixing the notion of "nothrow" and "safe", 
which are orthogonal concepts. Most logging frameworks "gag" 
their exceptions, which makes them nothrow.

This doesn't mean that exceptional things can't happen: It only 
means the exceptions will not "escape" from the call.


More information about the Digitalmars-d-learn mailing list