Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch practices: avoid losing catched exception information. #1555

Merged
merged 2 commits into from
Jan 25, 2018

Conversation

fredericDelaporte
Copy link
Member

@fredericDelaporte fredericDelaporte commented Jan 23, 2018

All catches have been reviewed for avoiding losing original exception information:

  • When another exception is raised, it should embed the original one as an inner exception.
  • Otherwise when re-thrown, it should be done without altering its original stack-trace.
    Preferred way is of course to use "throw;" in the catch clause without specifying the exception, but otherwise ReflectHelper provide a way to preserve the stack-trace.
  • Otherwise it should be transmitted to the logger.

Some cases still do not follow this pattern for avoiding being too noisy, like "Try" utilities, failure in
closing an already failed object, some "implemented by exception" features, ...

Copy link
Member Author

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also the converse subject: avoid being too noisy with exceptions.
Many cases log fully the exception then re-throw it (directly or as inner of another one). I think this is a bad pattern tending to bloat the logs, and it should be avoided: log at most a message in such case. But as this would reduce the available logs data, maybe should it be changed only for 6.0 in a separated PR.

@@ -362,8 +362,6 @@ private void DoCompile(IDictionary<string, string> replacements, bool shallow, S
}
catch ( RecognitionException e )
{
// we do not actually propogate ANTLRExceptions as a cause, so
// log it here for diagnostic purposes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many cases do propagate them as inner exception, so removing the comment, they are now all propagated.
But I let the log in place, as this could be considered as a (very minor) breaking change to remove logs.

All catches have been reviewed for avoiding losing original exception information:

 * When another exception is raised, it should embed the original one as an inner exception.
 * Otherwise when re-thrown, it should be done without altering its original stack-trace.
   Preferred way is of course to use "throw;" in the catch clause without specifying the exception, but otherwise ReflectHelper provide a way to preserve the stack-trace.
 * Otherwise it should be transmitted to the logger.

Some cases still do not follow this pattern for avoiding being too noisy, like "Try" utilities, failure in closing an already failed object, some "implemented by exception" features, ...
{
// ignore it; the incoming property could not be found so we
// cannot be sure what to do here. At the very least, the
// safest is to simply not apply any dereference toggling...
Log.Info(ex, "Unable to find property {0}, no dereference will be handled for it.", propertyName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shall be at Debug level. Info is too high.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for matching the other log. Not very important, so well:

  • change both to Debug?
  • just this one?
  • keep them both at Info?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just this one, thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@fredericDelaporte fredericDelaporte merged commit f0644cf into nhibernate:master Jan 25, 2018
@fredericDelaporte fredericDelaporte deleted the catch branch January 25, 2018 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants