B4J Question Error Happened in Resumable Subs not Caught in Application_Error

xulihang

Well-Known Member
Licensed User
Longtime User
I am using Application_Error event to capture all errors. But it cannot capture errors happened in resumable subs. Is there a way to fix this?


B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Log(Error)
    Log(StackTrace)
    Return False
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    wait for (test) complete (done As Object)
End Sub

Private Sub test As ResumableSub
    Sleep(0)
    Dim i As Int = "A"
    Return ""
End Sub

Sub Button1_Click
    xui.MsgboxAsync("Hello World!", "B4X")
End Sub
 

xulihang

Well-Known Member
Licensed User
Longtime User
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
The sleep(0) function seems to have an influence on the behavior.
If this function is before the line with the error then the application error subroutine is not executed.
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    wait for (test) complete (done As Object)
End Sub
Private Sub test As ResumableSub
    Dim i As Int = "A"               
    Sleep(0)
    Return ""
End Sub
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    LogColor(Error,xui.Color_Blue)
    LogColor(StackTrace,xui.Color_Magenta)
    Return False
End Sub
1763466544685.png
 
Upvote 0

xulihang

Well-Known Member
Licensed User
Longtime User
Are you testing this in Release mode?
Application_Error is only called in Release mode, it is not used in Debug
I am testing in release mode.
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
If this function is before the line with the error then the application error subroutine is not executed.
Good spot!
My guess is that it has something to do with the test sub returning (because of the Sleep(0)) before the line that causes the error.

These two threads may be related:
 
Upvote 0
Top