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

Reviewed and Redesigned Exception Handling (closes #446) #476

Merged
merged 121 commits into from
Apr 26, 2021

Conversation

NightOwl888
Copy link
Contributor

Closes #446.

This centralizes exception handling so it includes/excludes the corresponding exception types as in Java. There were also several bugs found where the wrong exception type was either being caught or thrown, and fixing them makes the tests run more consistently and may have even improved performance overall.

Full tests were added for all known exception types in .NET, NUnit, and Lucene.NET so we have confirmation that our error handlers will only catch the exception types they are supposed to for the general exception types:

  • Error
  • Throwable
  • Exception
  • RuntimeException
  • IOException
  • IllegalArgumentException
  • IndexOutOfBoundsException

Some of the exceptions (such as NullReferenceException, IndexOutOfRangeException, and FormatException) were factored out by checking to ensure the condition that causes the exception cannot occur.

Also, the ExceptionDispatchInfo class has been applied to Lucene's centralized error handling and background processing so we always get a full stack trace from the point where the exception began rather than a partial clue from where the exception was rethrown.

…ugh] attribute to all assertion methods so the debugger stops in the code that fails the assert not inside of the assert method
…or testing internal (affects only .NET Framework)
…ng Java exception types to their closest .NET equivalent. See apache#446.
… by the new exception types (much of this is just to keep tests green but will be removed again after the transition to the new exception handling).
…rrected this exception type, but marked it internal, since we only want users to catch ObjectDisposedException
…erted them to use our IsThrowable() extension method (see apache#446).
…d them to use our IsError() extension method (see apache#446).
…erted them to use our IsException() extension method (see apache#446). Added overload for printStackTrace() that accepts a TextWriter so we can specify another output.
…nverted them to use our IsIOException() extension method (see apache#446).
…use defensive checks to avoid IndexOutOfRangeException for control flow
…erTest: Added comment about removal of several lines of code that were there to work around JRE bugs.
…xtDoc(): Added comment about refactoring the method to avoid IndexOutOfRangeException
…:GetParent(): Changed logic to use proper guard clauses and changed exception type from IndexOutOfRangeException to ArgumentOutOfRangeException to be consistent with .NET.
…lementation of EnsureOpen() and refactored guard clauses to throw .NET argument exceptions and defensively check for out of range issues instead of catching exceptions and re-throwing them as a different exception.
…cumentation and changed implementation to correctly throw ArgumentOutOfRangeException in cases where it is pertinent.
… about SpatialContextFactory throwing ArgumentNullException rather than NullReferenceException
…to use ArgumentNullException instead of NullReferenceException and fixed other guard clauses that throw ArgumentOutOfRangeException to show the correct messages.
…ArgumentNullException rather than NullReferenceException
…o throw ArgumentNullException rather than NullReferenceException
…lause to throw an ArgumentNullException rather than a NullReferenceException
…eateNode(): Changed guard clause to throw ArgumentNullException instead of NullReferenceException
…SyntaxImpl::ReplaceIgnoreCase(): Changed guard clause to throw ArgumentNullException rather than NullReferenceException
…eption messages to match the variable name they refer to, since it had been renamed previously
…hrow InvalidOperationException instead of NullReferenceException when QueryNodeProcessor.PostProcessNode returns null
…nvalidOperationException rather than NullReferenceException when either GetFormatter() or GetScorer() return null.
…nted out catch blocks that were only used to work around Java issues that don't exist in .NET.
…d StringIndexOutOfBoundsException with static factory methods and added documentation to explain how to convert (see apache#446)
…we are not rethrowing inside of the catch block.
…CodePages dependency for .NET Core 2.1, as it is no longer a dependency of J2N.
…ption whereever Lucene thorws ParseException (see apache#446)
…ad catch block to catch types that correspond to RuntimeException using our IsRuntimeException() extension method.
…processors back to using FormatException, because that is the expected parse error in .NET (see apache#446)
…aining why the code is commented and updated it with information about ExceptionExtensions
…ng() to build wrapped exception to prevent unnecessary stack trace overhead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Review exception types thrown and in try/catch blocks
1 participant