RuntimeException.Stack how to use?

Hi,
I need a function where write a log.

Imagine the following situation:
Window1.open → call s1() → call s2() → call s3()

function s3()
Try
  Raise New OutOfBoundsException 'or any Exception in runtime
Catch
  listOfError
End Try

function listOfError()
Var errStack() As String = RuntimeException.Stack
Var listErrStack As String

For Each listOfStack As String In errStack
  listErrStack = listErrStack + listOfStack + " - "
Next

the error is:

Module2.listOfError, line 1
Static reference to instance method: call this on an instance of class RuntimeException.
Var errStack() As String = RuntimeException.Stack

Ok, I need use an istance…
But how ?

My favourite method is to delete a nil FolderItem:

 try
      dim f as FolderItem
      f.Remove
    catch err as NilObjectException
      dim theCleaner as new ErrorExceptionCleaner
      dim ExceptionStack as String = theCleaner.CleanStack(err)
      LogItem("Stack: " + CarbonModule.EndOfLineMacintosh + ExceptionStack + CarbonModule.EndOfLineMacintosh)
      LogItemToConsole(ExceptionStack)
    end try

Holler if you want the ErrorExceptionCleaner class. It should do what you want.

Here’s my method that writes the stack to my logfile. You have to pass the error to it.

Sub dumpStack (error As RuntimeException, errType As String)

Var  i, num as Integer, msg As String, errStack() As StackFrame

errStack = error.StackFrames ()

msg = "Error type: '" + errType + "', Stack: " + errStack(0).Name
writeLog (msg)

num = errStack.LastRowIndex

for i = 1 to num
  msg = "         " + errStack(i).Name
  writeLog (msg)
next

End Sub

Then in my UnhandledException handler I do thus:

Sub UnhandledException (error as RuntimeException)

// Saves the runtime stack traceback to the logfile.

Var  msg, type as String

type = Introspection.GetType(error).Name
msg  = "Error - fatal exception '" + type + "', number " + error.ErrorNumber.ToString
writeLog (msg)

msg = "  Reason: " + error.Reason
writeLog (msg)

msg = "  Message: " + error.Message
writeLog (msg)

dumpStack (error, "FATAL")

End Sub

(Boy, these forum colours are strange!)

Theres a bit more to it than that as there are some exceptions one should re-raise (such as ThreadEndException) but this is the general idea.

Perfect. With you I have found the solution.
I will then obviously implement. Thank you both !

I leave part of code for someone if they need it

Try
  Raise New OutOfBoundsException 'or any Exception in runtime
Catch err As RuntimeException
  listOfErrors(err)
End Try

function listOfErrors(err As RuntimeException)
Var listErrStack As String
For Each listOfStack As String In err.Stack
  listErrStack = listErrStack + listOfStack + " - " '-> Here I'll write a Log to fileErrorLog.txt
Next