Skip to content
Advertisement

UndeclaredThrowableException for custom Exceptions

I’m currently working on a project running a jboss backend server (server-ear:ear exploded artefact) and a java gui (java 11) as frontend.

The backend contains a java service bean which accesses a database server and throws a custom exception (extends exceptions), if the variable is not found. The GUI catches the custom exceptions with a try and catch block.

The code is build and run inside of Intellij + Maven.

If i try to execute the code following arrow pops up at runtime:

Thread AWT-EventQueue-0: null
java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy36.expandDbVar(Unknown Source)
...
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at ...ServiceLoggingInvocationHandler.invoke(ServiceLoggingInvocationHandler.java)
... 56 more
Caused by: ...utils.CustomException: Database Variable not found for id "input".
at deployment.server-ear.ear.some-ejb.jar//...DbVarSvcBean.expandDbVar(DbVarSvcBean.java)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.as.ee@20.0.0.Final//org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
...

The code itself is tested on multiple computers and for all of them the exceptions is catched correctly. (Only my pc is experiencing these issues).

The jboss server is added as application server in Intellji. The build configuration is jboss local with an server-ear:ear exploded artifact.

Every thing worked fine last week, but suddenly stopped working. I already tried resetting everything, clean installing it and even tried a clean pc setup with ubuntu.

I tried many different build settings, switched java versions, etc. Anyone got ideas what could cause this behavior?

Advertisement

Answer

So for anyone interested what the problem was:

Since we are using a custom logger (ServiceLoggingInvocationHandler) which try catched the exceptions of an invoke method, the catched exceptions were already wrapped with an invocation exception and were not the original exceptions. To solve the problem we needed to unwrap the exceptions again before forwarding them.

Since the logger was only used in debugging mode and only when specified the problem was only occurring for me.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement