Android Question [SOLVED] How to catch errors with try and catch for a whole application?

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

Is there a way to catch an error for a whole application with a single try and catch?

This is the example codes how to implement try and catch for a whole application, but it didn't work
Sample Try and Catch:
Sub Activity_Create(FirstTime As Boolean)   'Codes in Main Activity
    try
        Activity.LoadLayout("1")
       'do some process'
       StartActivity(SecondActivity)
    catch
       log(LastException)
    End Try

End Sub

In those code, try and catch only able to catch errors in Main Activity, but if there are errors in SecondActivity, errors won't be catched.
 

incendio

Well-Known Member
Licensed User
Longtime User
Application_Error is called when there is an unhandled error. You can return True to discard the error.
I tried again, these were the result :
1. Use ToastMessageShow and Return False in Application_Error to display error message to user -> Application was not closed if errors doesn't effect critical process.

2. Write error message to a file and set Return True -> Application forced closed, but I got the error file.
 
Last edited:
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Very nice question but to be honest better use Try Catch in every activity to know exactly what is wrong.
Lets say I use it that way in nearly every Sub.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…