Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Sep 16, 2019 11:30 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Application - Error handler
PostPosted: Sat Nov 26, 2011 9:53 am 
Offline
User avatar

Joined: Sat May 27, 2006 3:27 pm
Posts: 480
I wanted to share a simple code to use in your application to track down errors.

Mine looks like this when it logs it to a file

Code is below hope this helps

Quote:
UnhandledException: NilObjectException

Current date: 2011-11-26 09:37:44


Executable Name: My Application
Executable Path: C:\Documents and Settings\Owner\Desktop\****\Error Logs\Log - 2011-11-26 093744.txt

Executable Size: 4.77 MB
Executable ModificationDate: 2011-11-26 09:37:37
Executable CreationDate: 2011-11-26 09:33:00

UserName: ***
Computer Name: ***
OS Version: Windows XP Build 2600 Service Pack 2
ProcessorCount:1
Context:

Call Stack:

Stack:
MainWindow.MainWindow.PushButton1_Action%%o<MainWindow.MainWindow>o<PushButton>
Delegate.IM_Invoke%%o<PushButton>
AddHandler.Stub.15%%
Delegate.Invoke%%
Application._CallFunctionWithExceptionHandling%%o<Application>p
_Main
% main


1. Put this code in a buttons action event to make the app have a error

dim f as folderitem = nil
f.name = "hello"


2. Put this code in the apps Unhandled exception

Dim d As New Date
Dim f As New FolderItem
Dim CurrentDate As String = ReplaceAll( d.SQLDateTime , ":" , "" )

f = SpecialFolder.CurrentWorkingDirectory.Child( "Error Logs" )

If Not f.Exists Then
f.CreateAsFolder
End

f = SpecialFolder.CurrentWorkingDirectory.Child( "Error Logs" ).Child( "Log - " + CurrentDate + ".txt" )

Dim t As TextOutputStream = f.CreateTextFile

If t = NIL Then Return False

t.WriteLine "UnhandledException: " + Introspection.GetType(error).Name + EndOfLine
t.WriteLine "Current date: " + d.SQLDateTime + EndOfLine + EndOfLine
't.WriteLine "Executable Name: " + App.DisplayName
t.WriteLine "Executable Path: " + f.AbsolutePath + EndOfLine
't.WriteLine "Executable Size: " + BytesToString( App.ExecutableFile.Length )
t.WriteLine "Executable ModificationDate: " + App.ExecutableFile.ModificationDate.SQLDateTime
t.WriteLine "Executable CreationDate: " + App.ExecutableFile.CreationDate.SQLDateTime + EndOfLine
't.WriteLine "UserName: " + GetLoggedInUserName
't.WriteLine "Computer Name: " + GetComputerName
't.WriteLine "OS Version: " + OSVersionString
't.WriteLine "ProcessorCount:" + Str( NumberOfProcessors ) + EndOfLine
t.WriteLine "Call Stack: " + EndOfLine
t.WriteLine "Stack: " + EndOfLine + Join( error.Stack, EndOfLine)
t.Close

MsgBox "An error occured "+ Introspection.GetType(error).Name + EndOfLine + EndOfLine + "A error log has been saved under " + EndOfLine + f.AbsolutePath + EndOfLine + EndOfLine +"App will be closed."

f.Launch

Quit


Top
 Profile  
Reply with quote  
 Post subject: Re: Application - Error handler
PostPosted: Sat Nov 26, 2011 1:05 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
Excellent, thanks for the contribution! :)

Is there a reason you commented out some of the WriteLines in your code?

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Application - Error handler
PostPosted: Sun Nov 27, 2011 1:39 pm 
Offline

Joined: Tue Sep 19, 2006 5:10 pm
Posts: 179
I have been tracking a problem that has stopped me from using newer versions of RealStudio since 2009r5.1. This is in bug report 14990 - "Reading Recordset field fails after reading another field succesfully. No errors reported. Application quits" currently ranked 192. I am currently using 2011r3 - OSX 10.6.8.

I never thought of implementing such a strategy in the UnhandledException EventHandler in App. Being a bit excited now I could see where I could grab some data from the crash using this technique. However my excitement was quickly dashed when I ran the app, it crashed and no file was created. I added a stop in the debugger upon entering UnhandledException and that stop was never reached.

Bummer. I need a fix for this crash so I can move all my apps into the newer releases. I just sent in the latest crash in hopes RS can solve this problem very soon.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group