Review of Jose Armando Garcia Sancio's std.log
Jonathan M Davis
jmdavisProg at gmx.com
Tue Mar 6 19:43:47 PST 2012
On Tuesday, March 06, 2012 19:27:35 Andrei Alexandrescu wrote:
> On 3/6/12 7:04 PM, Jonathan M Davis wrote:
> > On Tuesday, March 06, 2012 18:19:23 Jose Armando Garcia wrote:
> >> Fatal and Critical are exactly these continence functions... To
> >> reiterate. fatal will always assert and critical will always throw. It
> >> is impossible for the user to disable these things.
> >
> > No, because they affect the log level. The concept of throwing and the log
> > level should be _completely_ separate.
>
> Why?
Because the level that you log something at and what you want to do in terms
of exceptions aren't necessarily related at all. It could easily be that you
want to log something and then do some series of operations before throwing -
even if the log level is the most severe level, and you intend to throw an
Error to kill the program. And as others have pointed out, you might want to
log a series of messages. Having std.log throw on the first one makes it so
that you can't log any others.
> > std.log shouldn't be declaring _any_
> > exception types unless they're related to setting up the logging (_none_
> > which relate to functions which log).
>
> Why?
Because as others have asserted, logging should not affect program flow. It's
printing out messages to a log, which doesn't necessarily have _anything_ to
do with throwing exceptions. It's merely for providing information about what
the program is doing. If you have it throwing exceptions - _especially_
exceptions which are specific to it - you're conflating two separate concepts:
logging to a log file and having the program report errors. They _can_ be
related, but they often aren't.
And when you _do_ throw an exception, why on earth would anyone want a
LoggingException (or whatever std.log would call its exception type)? You want
an exception which relates to what went wrong, not what threw it. The fact
that you logged a message before throwing is incidental. Nothing that catches
the exception is going to care.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list