Suddenly I am seeing my app close spontaneously. Unfortunately, by the time I can trap it, it already is in the App.Close Event. The Session.Close event does fire before App.Close event - I think…
Can anyone suggest where to start looking for the cause of this behavior?
If there’s still an active session, then the framework shouldn’t be closing the app. You may be hitting an unhandled exception. Do you have an UnhandledException event in your session class? That might shed some light on what’s going on.
It looks like the Session.close is NOT related the main problem of App.Close.
I started seeing Session.Close when I was doing debugging. If there were any tables left open, they would automatically create a new session (as they should). Closing the tab caused the Session.close which is how it should be,
I have this in the session.unhandled…
Dim Flds() As String = Array(“EXCEPTION”, CurrentMethodName , CStr( error.Type) + " Err Msg = " + Error.Message )
Logs.AddFields Flds
Logs.LogFileAppend( Logs.K_Trace_App)
Return False
I have this is the App.Unhandled…
System.DebugLog( "Unknown exception in: " + CurrentMethodName + " no error type available " + CStr( error.Type) + " Err Msg = " + Error.Message )
Return False
It depends. If you return false, the app will close after an exception occurs. Returning true will prevent that but only you can decide if that means your app is in an unstable state.
In app.close. By raising the exception, you can capture the stack trace that got it there. It may be helpful in diagnosing the problem. No guarantees, though. We’re still grasping at straws.
Thanks guys.
I put the code in the App.Close Event. This is the code… When it hits the line to raise the event, it goes right down to the Exception e as RuntimeException
Sub Close()
// App.Close
// Call UPnP.Router_ClosePort(0)
Raise New OutOfBoundsException
Dim Flds() As String = Array(“APP - SHUT DOWN”, CurrentMethodName , “”)
Logs.AddFields Flds
Logs.LogFileAppend( Logs.K_Except_App_Err )
return
// GPIO.DigitalWrite( k_GPIO_GUI_On, GPIO.Off )
Exception e as RuntimeException
Flds() = array(“EXCEPTION”, CurrentMethodName, Cstr( e.Type) )
Logs.AddFields Flds
Logs.LogFileAppend( Logs.K_Except_App_Err)
End Sub
Uh yeah, you need to wrap the exception in a try-catch and in the catch, that’s where you grab and log the stack… because the manufactured exception shouldn’t be treated as an exception.
Raising the exception should be the last thing you do in your “normal” code. In place of the “return” line. Then in your exception handler, you should log the contents of e.Stack.
We are manufacturing an exception (via raise new OutOfBoundsException) purely to get to the contents of the stack. There are 2 ways to do this, with Exception e as OutOfBoundsException (be explicit here), or with Try/Catch as Greg suggests.
Dude. If you’re giving advice, read the code after. That’s not going to compile without the “e”
@Tim_Seyfarth
You don’t need both if you’re going to raise the exception at the end and allow it to crash. What I was suggesting was to simply use a tight scoped exception handler for getting the stack and not change any other code in your method. That would look like this:
Try
Raise New OutOfBoundsException
Catch e as OutOfBoundsException
Dim st() as string = e.stack
Break
// write the stack to a log for runtime use
Logs.AddFields st
End Try