[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.newcomer] Re: Who should log an Exception
|
"Felix Dorner" <felix_do@xxxxxx> wrote in message
news:gs2cbl$idc$1@xxxxxxxxxxxxxxxxxxxx
> Felix Dorner wrote:
>>Now it happens to be the case that the other plug-in also logged that
>>exception (in this concrete case I refer to
>>org.eclipse.core.ant.AntRunner) so I get the same thing twice in the error
>>log.
>
> Well actually the AntRunner just throws the exception without logging it.
> I was blinded by seeing org.eclipse.core.ant in the error log. This
> happened because I wrapped the catched CoreException into an IStatus which
> I sent to the log. That CoreException contains an IStatus (wow, I didn't
> know that..) So the log just displayed an entry with my status at the root
> and the wrapped IStatus of the ant plugin as its child.
>
> Puh, anyway, the question's still there..
IMHO this is one of those questions that has no correct answer in any
real-world environment - we can argue about what the best answer "would" be
in a perfect world but realistically there is no way to apply the standard.
My own feeling is that it rarely makes sense to log exceptions if you're
going to rethrow them, unless you are in a position to say something
interesting about the exception. For instance, in my annotation processing
code, I may know what annotation processor was being called and what code it
was being called on; logging that information, along with the exception,
could help someone debug a problem that would not be obvious if all they had
was the stack trace.
So the question to ask is "assuming that this exception is also going to get
logged somewhere else, does it still make sense for me to log it also?".
If you're handling rather than rethrowing the exception, that's different.
For instance, in some of the annotation processing code we catch exceptions
thrown by processors and instead turn them into problem markers. That way
if the problem is fixed (e.g., by editing the code being processed), the
problem marker goes away rather than being accumulated in the log.
It's really annoying to have a log full of the same exception over and over,
especially if it's something that is basically innocuous.