Skip to content

Commit

Permalink
Changed: Exception handlers now search through superclasses.
Browse files Browse the repository at this point in the history
  • Loading branch information
MTrop committed Feb 8, 2021
1 parent d5b5e87 commit 4071cd6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Small (C) Black Rook Software 2020
by Matt Tropiano et al. (see AUTHORS.txt)


Changed in 1.5.4
----------------

- `Changed` Exception handlers now search through superclasses for matching handlers.


Changed in 1.5.3
----------------

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/blackrook/small/SmallEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,12 @@ public boolean handleView(HttpServletRequest request, HttpServletResponse respon
public <T extends Throwable> boolean handleException(HttpServletRequest request, HttpServletResponse response, T throwable)
{
ExceptionHandler<T> handler;
if ((handler = (ExceptionHandler<T>)exceptionHandlerMap.get(throwable.getClass())) != null)
Class<?> exceptionClass = throwable.getClass();

while ((handler = (ExceptionHandler<T>)exceptionHandlerMap.get(exceptionClass)) == null && exceptionClass != Object.class)
exceptionClass = exceptionClass.getSuperclass();

if (handler != null)
{
handler.handleException(request, response, throwable);
return true;
Expand Down

0 comments on commit 4071cd6

Please sign in to comment.