Trapping exception errors

It appears that when a exception error (a NilObjectException as an example) occurs, the entire application shuts down, but no message displays and therefore the user has no idea to report anything. They just think they lost connection and need to restart. They are frustrated by the lack of stability but since this is not distinguishable from anything else, progress on finding it (and a fix) are remote.

So here is my question, can I trap an Exception error at any level? It appears from the documentation, that the exception must be trapped in the method itself. Any suggestions on logging or some other mechanism that I can use to find these issues that are not showing up in my testing, but the users are experiencing, but do not report.


Use the UnhandledException event of the project to catch the exception.
All exceptions that weren’t caught at the other levels will end up,over there.

Unhandled exceptions should display a dialog similar to this:

See WebApplication.UnhandledException for more information.

This particular exception causes the program to quit. When I finally found out that this was caused by an exception, I could reproduce it. It closed the application if I “continued” in the debugger and never got a chance to display the message?

This is what the user was seeing. Just gave the standard session message on disconnect.

Thanks for the tip, Dirk. At least the user will know something odd happened and to email me some info.

@Dan Harding - As Dirk and Paul pointed out, you must put code in the App.UnhandledException event and then Return True if you don’t want the app to crash.

Almost there. If I deploy the applciation, it records the exception, but not the stack. Is there a way to deploy the application so that the stack is available to be printed out?

I have this pretty roughly and badly written piece of code in my app.unhandled exeption event… It will create a text file next to the executable and append errors…

Its copy and pasted and edited by myself from the language reference and various places all over the www…

[code] dim f as new FolderItem( “ErrorDump.txt” )
dim out as TextOutputStream = f.CreateTextFile
dim errmsg as string
dim extension as string
dim heute as new date
dim os as string
dim path as string

if out = nil then return false

'get os
#if TargetMacOS
OS = “Mac OS”

//be more specific of OS Version
dim sys1, sys2, sys3 as Integer
call System.Gestalt("sys1", sys1)
call System.Gestalt("sys2", sys2)
call System.Gestalt("sys3", sys3)

select case sys1
case 10
  os = "Mac OSX"
  select case sys2
  case 0
    os = "Mac OSX Chetaah"
  case 1
    os = "Mac OSX Puma"
  case 2
    os = "Mac OSX Jaguar"
  case 3
    os = "Mac OSX Panther"
  case 4
    os = "Mac OSX Tiger"
  case 5
    os = "Mac OSX Leopard"
  case 6
    os = "Mac OSX Snow Leopard"
  case 7
    os = "Mac OSX Lion"
  case 8
    os = "Mac OSX Mountain Lion"
  case 9
    os = "Mac OSX Mavericks"
  end select
end select

os = os + " "+str(sys1)+"."+str(sys2)+"."+str(sys3)

#elseif TargetWin32
OS = “Windows”

//try to be more specific of windows version
Soft Declare Sub GetVersionExA lib "Kernel32" ( info as Ptr )
Soft Declare Sub GetVersionExW lib "Kernel32" ( info as Ptr )

dim info as MemoryBlock

if System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) then
  info =  new MemoryBlock( 20 + (2 * 128) )
  info.Long( 0 ) = info.Size
  GetVersionExW( info )
  info =  new MemoryBlock( 148 )
  info.Long( 0 ) = info.Size
  GetVersionExA( info )
end if

dim str as String

if info.Long( 4 ) = 4 then
  if info.Long( 8 ) = 0 then
    os = "Windows 95/NT 4.0"
  elseif info.Long( 8 ) = 10 then
    os = "Windows 98"
  elseif info.Long( 8 ) = 90 then
    os = "Windows Me"
  end if
elseif info.Long( 4 ) = 3 then
  os = "Windows NT 3.51"
elseif info.Long( 4 ) = 5 then
  if info.Long( 8 ) = 0 then
    os = "Windows 2000"
  elseif info.Long( 8 ) = 1 then
    os = "Windows XP"
  elseif info.Long( 8 ) = 2 then
    os = "Windows Server 2003"
  end if
elseif info.long(4) = 6 then
  if info.long(8) = 0 then
    os = "Windows Vista"
  elseif info.long(8) = 1 then
    os = "Windows 7"
  end if
end if

str = " Build " + Str( info.Long( 12 ) )

if System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) then
  str = str + " " + Trim( info.WString( 20 ) )
  str = str + " " + Trim( info.CString( 20 ) )
end if

os = os + str

#elseif TargetLinux
OS = “Linux”
path = “”

out.WriteLine “System Information:”+EndOfLine

out.WriteLine "Operating System " +os
out.WriteLine "Build# " + str(app.NonReleaseVersion)
out.WriteLine "Build Date "+str(app.BuildDate.SQLDateTime)+EndOfLine
out.WriteLine "UnhandledException: " + Str(error.ErrorNumber) + error.Message + EndOfLine
out.WriteLine "Stack: " + EndOfLine + Join(error.Stack, EndOfLine) + EndOfLine

dim memoryUsed as Integer = Runtime.MemoryUsed
out.WriteLine( “Memory Used: " + Str( memoryUsed ) + " used in heap1” )

dim objCount as Integer = Runtime.ObjectCount
out.WriteLine( Str( objCount ) + " objects" )

Dim i, total as Integer
For i=0 to total-1
out.WriteLine Str(Runtime.ObjectID(i)) + " " + Runtime.ObjectClass(i) + " " + Str(Runtime.ObjectRefs(i))


print “Sorry, but apparently my programmer seems to be a little stupid, when it comes to exeptions.” + EndOfLine + EndOfLine+ "I have created a dumpfile at " + app.ExecutableFile.parent.AbsolutePath + “ErrorDump.txt” + EndOfLine + endofline+ “Please send it to me”