What's the best way to handle unhandled exceptions

I was wondering if you get an unhandled exception if you should shut down the session or the entire app.

If there is an exception in one session, can that affect other sessions, make them unstable?

Thanks

We tend not to shut them down. However, depending upon your application this may not be appropriate behavior. It’s quite possible that your application is in a weird or unknown state that it can’t recover from.

In the long run, it’s up to you figure out the risks involved to your users.

Let’s say you have a record set that comes back null and that’s what caused it, would that put other sessions at risk. The recordset is a local var to the function and the database is a session variable.

Two comments:

One, if the recordset is coming back nil, you have an SQL error. You should always check for the database error. ALWAYS!

Two, if everything is local to the session then other sessions should not be affected.

To underscore Bob’s comment, you should be handling that through defensive code so, by definition, it should never be an UNhandled exception.

I know that was just an example, the only thing that I could think of. I do check for that.

Is there any way to determine what caused an Unhandled NilObjectException?

Occasionally I have an app that for some reason starts throwing an Internal Server Error and I’m trying to figure out what is causing it.

An app may run fine for a month, then suddenly cause this error.

Another question, is there a way an app can check to see if there are any more of its sessions running and if they are dormant, no user input or activity.

I also was wondering if there was a way to check for the internal server error before it is displayed to user, but couldn’t think of any way to do that.

You can find out WHERE a Xojo unhanded exception happened by looking at the Error.Stack.

Do you have a timeout on the session? That should close sessions if they are inactive. But, in general, you can see how many sessions are open and you can iterate through them and look at variables. I have an admin page that does just this just to see who’s logged in. Technically you can quit a session but every time I’ve tried this in the past it ended up killing my own session (I have not gone back to look at this in recent builds though).

The Server Error is much trickier to find. Is this a cgi app or standalone? What database are you using? What’s the OS?

I saw in the error log the stack as to where the error happened.

These are cgi apps and I have a lot of them, like 15 all do something different for our membership.

I do have a session time out, though I’m not sure what the best value would be.

I do find from time to time an app that just remains in memory.

If I could go through the a list of sessions, Ideally if I found one that I could determine has been running to long and I could kill it then maybe it would cut down on these Internal Server errors.

Is there any examples of going through active sessions anywhere?

Thanks for your input Bob.

http://documentation.xojo.com/index.php/WebApplication.SessionAtIndex

A little confused.

For i As Integer = 0 To App.SessionCount-1
  App.SessionAtIndex(i).MsgBox("App shutdown.")
Next

Is this all apps or the app that the procedure is in? How do you look for a specific app.

[quote=236101:@Richard Albrecht]A little confused.

For i As Integer = 0 To App.SessionCount-1
  App.SessionAtIndex(i).MsgBox("App shutdown.")
Next

Is this all apps or the app that the procedure is in? How do you look for a specific app.[/quote]
You can’t code across apps. Sessions yes.

That said, if your app doesn’t quit, you probably either have users connected, a long process running or a memory leak.

It definatly is not a case of having users connected or a long running process.

If it were a memory leak wouldn’t it be consistent. It’s not any single app and its not often they stay in memory.

My very simple test app I posted in another thread was nothing but a web page and it stayed in memory for More than a week.

Remember. Any connection to your app, regardless of whether it’s a user or not, will spawn a session and hold the app open for another 3 minutes.

My test app had no connections. I’m the only one with the url and I had rebooted my machine several times.