Hi,
i have a question about try-catch-blocks. I want to catch all errors and jump to a diagnostic-page. That´s working so far - but with a little limitation. I have my class-modules and my code modules. When i have a try-catch on my class and call a function from there which also have a try-catch and raises an error the outer catch fires. Can i prevent this?
B4X:
sub a()
Try
'do anything
result=codeModule.b
Catch
Dim ex As errorHandler = B4XPages.GetPage("errorhandler")
ex.showError("moduleA","sub_A",LastException) '<- this fires
End Try
end sub
...
sub b() as int
Try
'do anything
'raise error '<- here is an error
return anything
Catch
Dim ex As errorHandler = B4XPages.GetPage("errorhandler")
ex.showError("moduleB","sub_B",LastException) '<- this is what i want to see
End Try
end sub
Is the error you get in a() the same as in b()? You don't seem to be returning a value when an error happens in b(), which could create a new error in a().
I walked through the section and see the problem. The inner block fires, but it did not stop - so the outer catch also fires and overwrites the message.
The showError-Sub contains following:
B4X:
Sub showError(module As String, operation As String, error As String)
Mo.text=module
op.Text=operation
err.Text=error
B4XPages.ShowPageAndRemovePreviousPages("errorhandler")
End Sub
How can i stop the app after showing the error-screen?
If you want to stop the program after an error happens then you should let the app crash. You can handle the Application_Error event in the starter service if you want to do something right before the crash.