### Capture LastException StackTrace

THis is an example to capture the LastException Stacktrace as a string using Inline Java.
`Sub Process_Globals
Private joInline As JavaObject = Me
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
ExceptionTest
End Sub`
`Sub ExceptionTest
Dim imgView As ImageView
imgView.Initialize("")
Try
imgView.SetImage(fx.LoadImage(File.DirAssets, "myimage.png"))
Catch
Log(LastException.Message)
Log(joInline.RunMethod("GetExceptionString", Array(LastException)))
End Try
End Sub`
If JAVA
import java.io.PrintWriter;
import java.io.StringWriter;
/*
* Convert Exception Stacktrace to String in Java, use printStackTrace(PrintWrite pw) method of Throwable class.
*/
public static String GetExceptionString(Exception e){
//Create new StringWriter object
StringWriter sw = new StringWriter();
//Create PrintWriter for StringWriter
PrintWriter pw = new PrintWriter(sw);
//Print the exception stacktrace to PrintWriter
e.printStackTrace(pw);
//Use toString method to get stacktrace to String from StringWriter object
return sw.toString();
}
End If

Changed: , Category: Try Catch Exception, File: T6C273M2028.htm, ID: 2028