Android Question try-catch inside try-catch

TheRealMatze

Active Member
Licensed User
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

Regards
 

Spavlyuk

Active Member
Licensed User
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().
 
Upvote 0

TheRealMatze

Active Member
Licensed User
I'm not sure that I understood. An error in b() will cause the catch in b() to catch the error. Add some log messages to better understand it.

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?
 
Upvote 0

TheRealMatze

Active Member
Licensed User
If you want to stop the program after an error happens then you should let the app crash.
not exactly what i want... is this the "normal" way?

You can handle the Application_Error event in the starter service if you want to do something right before the crash.
In the starter-service? I think i don´t have one...
Edit: Is there, was hidden... I take a look at it. Thanks!
 
Last edited:
Upvote 0

TheRealMatze

Active Member
Licensed User
The starter-service is only in android, right? maybe that´s why i didn´t noticed it. is there a equivalent for ios?
 
Upvote 0

TheRealMatze

Active Member
Licensed User
It is an Android feature. There is no equivalent feature in B4i and you cannot "stop" the app. Apple doesn't allow it.

You posted it in the Android forum. For iOS the best way to manage crashes is with KSCrash framework.
Thanks. In this case i remove the error-handling complete and let the app crash - normaly there is no point to crash...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…