B4J Question class java.lang.Error cannot be cast to class java.lang.Exception ?

tchart

Well-Known Member
Licensed User
Longtime User
I have a try/catch block in a B4J project.

In the catch code Im just using this; Log(LastException)

But this is causing an exception of its own and the app is crashing. In the logs is the following;

B4X:
Caused by: java.lang.ClassCastException: class java.lang.Error cannot be cast to class java.lang.Exception (java.lang.Error and java.lang.Exception are in module java.base of loader 'bootstrap')
    at anywheresoftware.b4a.BA.setLastException(BA.java:360)
    at nz.ope.qonda.monitor.agent.bkg_collect_hostinfo._collect(bkg_collect_hostinfo.java:63)
    at nz.ope.qonda.monitor.agent.bkg_collect_hostinfo._timer1_tick(bkg_collect_hostinfo.java:101)
    at jdk.internal.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    ... 12 more

Any idea why Log(LastException) isnt working in this case?
 

tchart

Well-Known Member
Licensed User
Longtime User
Erel, Im not 100% sure. Im using a library method to retrieve server process information on a timer, I believe its this method that is causing the error but this is kind of expected as the information Im retrieving may not be there on every tick (i.e a process may have been terminated).

I was mainly curious why it was returning an Error instead of an Exception.

For now Ive commented out the Log(LastException) line and I will monitor to see how it behaves now.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…