Android Question Is it possible to log Modle, Sub and error line of unhandled runtime error?

Discussion in 'Android Questions' started by RB Smissaert, May 4, 2019.

Tags:
  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Currently doing a simple error log for unhandled runtime errors:

    Code:
    'Return true to allow the OS default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
     
     LogError(Error.Message)
     
    Return True
     
    End Sub

    Sub LogError(strErrorMsg As String)
     
     
    Dim str As String
     
    Dim strCurrentDateTime As String
     
    Dim strDateFormat As String
     
     
    'keep the current date format
     strDateFormat = DateTime.DateFormat
     
    DateTime.DateFormat = "EEE, d/MMM/yyyy HH:mm:ss"
     strCurrentDateTime = 
    DateTime.Date(DateTime.Now)
     
     str = 
    File.ReadString(strAppDir, "AppLog.txt")
     
     
    If str.Length = 0 Then
      
    File.WriteString(strAppDir, "AppLog.txt", strCurrentDateTime & CRLF & strErrorMsg)
     
    Else
      
    File.WriteString(strAppDir, "AppLog.txt", str & CRLF & CRLF & strCurrentDateTime & CRLF & strErrorMsg)
     
    End If
     
     
    DateTime.DateFormat = strDateFormat
     
    End Sub
    Is it possible to add some more information, eg module, sub and error line?

    RBS
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Thanks, will keep that in mind.
    I think for now I can do it simpler by just parsing out the error Sub from the StackTrace as in
    Sub Application_Error (Error As Exception, StackTrace As String) As Boolean:

    Code:
    Sub GetErrorSubFromStackTrace(strStackTrace As StringAs String
     
    Dim iPos1 As Int
     
    Dim iPos2 As Int
     iPos1 = strStackTrace.IndexOf(
    "b4a.sqlitelight1.") + 17
     iPos2 = strStackTrace.IndexOf2(
    "(", iPos1)
     
    Return strStackTrace.SubString2(iPos1, iPos2).Replace("_""")
    End Sub
    I take it it is not possible to get the B4A error line, from runtime data, unless you log every code line that runs,
    but that would be too much trouble.

    RBS
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The line number is not available at runtime.
     
  5. JohnC

    JohnC Well-Known Member Licensed User

    What is this reference to sqlitelight1 for?

    Is this GetErrorSubFromStackTrace routine custom designed for you app and that's why it includes the sqlitelight1 reference?

    Or is this reference needed for use with any b4a app?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice