Is it possible to handle an exception thrown in an resumable sub?
Example:
B4X:
Sub throwAndResumableSubTest
Log("Aufrufer startet")
Try
Wait For (resumableAndThrowing) Complete
Catch
Log(LastException)
End Try
Log("Aufrufer endet")
End Sub
Sub resumableAndThrowing As ResumableSub
Log("ResumableSub startet")
Sleep(100)
Dim ex As ExceptionEx
ex.Initialize("Meine eigene Ausnahme.")
ex.Throw
Log("ResumableSub endet")
Return 0
End Sub
Since the second sub already returned when the exeption is thrown, the try...catch block can't handle it. The app crashes.
Note that the Complete event should include the result parameter:
B4X:
Wait For (resumableAndThrowing) Complete (Unused As Int)
You will need to catch the error inside the resumable sub. You can change your code to:
B4X:
Sub throwAndResumableSubTest
Log("Aufrufer startet")
Wait For (resumableAndThrowing) Complete (Success As Boolean)
Log("Aufrufer endet")
End Sub
Sub resumableAndThrowing As ResumableSub
Try
Log("ResumableSub startet")
Sleep(100)
Dim ex As ExceptionEx
ex.Initialize("Meine eigene Ausnahme.")
ex.Throw
Catch
Return False
End Try
Log("ResumableSub endet")
Return True
End Sub
Hm, ok... I wanted to use Exceptions for error handling, so I don't have to handle the error for each and every sub I call.
It seems I have to use another method then.