Skip to content

Commit

Permalink
[jsscripting] Wrap and rethrow other exceptions instead of returning …
Browse files Browse the repository at this point in the history
…them

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 committed Dec 14, 2022
1 parent df17c75 commit 8a6834d
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.openhab.automation.jsscripting.internal.scriptengine;

import java.io.Reader;
import java.lang.reflect.UndeclaredThrowableException;

import javax.script.Bindings;
import javax.script.Invocable;
Expand Down Expand Up @@ -124,7 +125,7 @@ public Object invokeMethod(Object o, String s, Object... objects)
} catch (IllegalArgumentException e) {
throw (IllegalArgumentException) afterInvocation(e);
} catch (Exception e) {
return afterInvocation(e); // Avoid "missing return statement" warnings
throw new UndeclaredThrowableException((Exception) afterInvocation(e)); // Wrap and rethrow other exceptions
}
}

Expand All @@ -144,7 +145,7 @@ public Object invokeFunction(String s, Object... objects)
} catch (NullPointerException e) {
throw (NullPointerException) afterInvocation(e);
} catch (Exception e) {
return afterInvocation(e); // Avoid "missing return statement" warnings
throw new UndeclaredThrowableException((Exception) afterInvocation(e)); // Wrap and rethrow other exceptions
}
}
}

0 comments on commit 8a6834d

Please sign in to comment.