On 3/6/12 7:43 PM, Jonathan M Davis wrote:
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.

Then I guess you'd be well advised to use the function that "logs to the error log", not the one that "logs to the error log and then throws". No? I mean you're explaining how a screwdriver is not appropriate for pounding nails.

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 does, because, as I mentioned, frequently one is interested in logging erroneous events that are followed by a breakage of flow.

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.

Well all I can say is they are in my experience. Some logging libraries have primitives that throw, some don't. I prefer a library that has the option in it because I use it all the time with glog.

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.

That I do agree with.


Andrei

Reply via email to