From 4071cd66cced46ce655ec62c14b384ef7b7baa8b Mon Sep 17 00:00:00 2001 From: mtrop Date: Sun, 7 Feb 2021 22:16:59 -0500 Subject: [PATCH] Changed: Exception handlers now search through superclasses. --- docs/CHANGELOG.md | 6 ++++++ src/main/java/com/blackrook/small/SmallEnvironment.java | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 5246b61..7d20361 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 ---------------- diff --git a/src/main/java/com/blackrook/small/SmallEnvironment.java b/src/main/java/com/blackrook/small/SmallEnvironment.java index 668171b..2063cf3 100644 --- a/src/main/java/com/blackrook/small/SmallEnvironment.java +++ b/src/main/java/com/blackrook/small/SmallEnvironment.java @@ -608,7 +608,12 @@ public boolean handleView(HttpServletRequest request, HttpServletResponse respon public boolean handleException(HttpServletRequest request, HttpServletResponse response, T throwable) { ExceptionHandler handler; - if ((handler = (ExceptionHandler)exceptionHandlerMap.get(throwable.getClass())) != null) + Class exceptionClass = throwable.getClass(); + + while ((handler = (ExceptionHandler)exceptionHandlerMap.get(exceptionClass)) == null && exceptionClass != Object.class) + exceptionClass = exceptionClass.getSuperclass(); + + if (handler != null) { handler.handleException(request, response, throwable); return true;