Android Tutorial Uncaught Exceptions

EvgenyB4A

Active Member
Licensed User
Longtime User
Hi
I want to send an error by HTTP but the server doesn't get anyting
The code is below:

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
'wait for 500ms to allow the logs to be updated.
Dim jo As JavaObject
Dim l As Long = 500
jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
logcat.LogCatStop
logs.Append(StackTrace)

' Dim email As Email
' email.To.Add(emailAddress)
' email.Subject = "Program crashed"
' email.Body = logs
' StartActivity(email.GetIntent)

Log("EEERRor " & Main.LinkToServer & " " & Main.DeviceID)

Dim job1 As HttpJob

job1.Initialize("RuntErr", Me)

job1.PostString(Main.LinkToServer & "/" ,"ID=" & Main.DeviceID & "&case=RunTimeError" & "&Details=" & logs)

job1.GetRequest.Timeout = 32000
ToastMessageShow(logs,True)

Return True
End Sub

Sub Service_Destroy

End Sub

Sub JobDone (Job As HttpJob)
Log("AAA")
ExitApplication
End Sub
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I was doing something close to what you are doing and had issues. What I ended up doing was writing a file out and on the next run of the program check for the file and send it then. That seems to work much better.
 

peacemaker

Expert
Licensed User
Longtime User
Is it possible to have timestamps in the system log lines ?
 

peacemaker

Expert
Licensed User
Longtime User
Yes, it's about Application_Error, just more detailed log info - is possible ?
 

peacemaker

Expert
Licensed User
Longtime User
Just add into logs.Append(StackTrace) some timestamps
 

Alpandino

Member
Licensed User
Hi,
in my Starter Module I have Application_Error Sub, with Return True, but when my app crashes (every now and then) the user can't see the message asking permission of the user to send a report to Developer Console. The user can see only a message saying: "The app stops unexpectedly" or similar.
I need this kind of report.
Any help or suggestion?
 

FrankBerra

Active Member
Licensed User
Longtime User
I am using the following code in the soubroutine:
B4X:
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
    logcat.LogCatStop
    logs.Append(StackTrace)
    File.WriteString(File.DirDefaultExternal, "CrashReport.txt", logs)
    File.WriteString(File.DirDefaultExternal, "CrashReport.txt", Chr(10) & Chr(10) & "============================" & Chr(10) & Chr(10))
    Return True
End Sub

When something wrong happens the file CrashReport.txt contains just the line "============================".
Where i am wrong? How can i log something more useful?
 

FrankBerra

Active Member
Licensed User
Longtime User
Yes i see the logs in a new email, but i can't save them in a local file.

For example i am using the following code:

B4X:
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean 'Istruzioni prese da qua: https://www.b4x.com/android/forum/threads/uncaught-exceptions.59805/
        'wait for 500ms to allow the logs to be updated.
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l)) 
    logcat.LogCatStop
    logs.Append(StackTrace)
    File.WriteString(File.DirDefaultExternal, "CrashReport.txt", logs.ToString)
    File.WriteString(File.DirDefaultExternal, "CrashReport.txt", Chr(10) & Chr(10) & "=============" & Chr(10) & Chr(10))
   
    Dim email As Email
    email.To.Add("MyEmail@aaa.com")
    email.Subject = "Program crashed"
    email.Body = logs.ToString
    StartActivity(email.GetIntent)
   
    Return True
End Sub

The email body contains the correct information while the file CrashReport.txt contains just "============="

Where i am wrong?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…