Note that these two features are currently available in B4A and B4J, and will soon be added to B4i.
ThrowException:
Code:
Public Sub SumPositiveNumbers(x As Int, y As Int) As Int
If x <= 0 Or y <= 0 Then
ThrowException("Parameters must be positive.")
End If
Return x + y
End Sub
StackTrace:
Code:
Try
Dim z As Int = SumPositiveNumbers(1, -2)
'...
Catch
Log(LastException)
Log(LastException.StackTrace)
End Try
(RuntimeException) java.lang.RuntimeException: Parameters must be positive.
java.lang.RuntimeException: Parameters must be positive.
at anywheresoftware.b4a.keywords.Common.ThrowException(Common.java:682)
at b4j.example.main._sumpositivenumbers(main.java:101) <---------------- useful information here
at b4j.example.main._appstart(main.java:59)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:117)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:104)
at b4j.example.main.start(main.java:37)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Stack traces are more meaningful in release mode.