Hi guys, For some reason when my app is a .exe file it randomly stops responding and crashes every now and then but does not display why. does anyone know how I can make it print the reason why it crashed into a text file?
Thanks
Jamie.
Printable View
Hi guys, For some reason when my app is a .exe file it randomly stops responding and crashes every now and then but does not display why. does anyone know how I can make it print the reason why it crashed into a text file?
Thanks
Jamie.
Only if you're tracing your code with error-handlers.
Then it's pretty easy to implement an error-log.
If you don't have errorhandlers, then your only option would be the event-log of Windows.
Thanks, How do I add error-handlers? Basically the team just want to be able to see which errors are causing the app to crash, so we can fix them.
Ta
The very basic errorhandler is something like this
vb Code:
Public Sub Something() On Error Goto ErrorHandler 'DoSomething 'DoSomethingElse ErrorHandler: FileNumber = FreeFile Open "Error.log" For Output As #FileNumber Print#FileNum, "Error in Function Something: " & Err.Number & " - " & Err.Description Close#FileNum 'Resume or Exit Sub or blame Microsoft or whatever else End Sub
Fantastic, Where would be the best place to put that code? I mean will i have to put it on every public sub to catch an error? or is it possible to have it in one general place?
thanks
If you pose this question to 5 programmers, you will get 5 different answers :D
I'm doing it like this:
vb Code:
'In a public Module Public Sub ErrorHandler(ByRef FunctionName As String, ByVal, ErrNumber As Long, ByRef ErrDescription As String) Dim FileNumber As Integer FileNumber = FreeFile Open MyExePath & "\error.log" For Append As #FileNumber Print#FileNumber, "Date/Time of Error: " & Format(Now,"YYYY.MM.DD HH:MM:SS") Print#FileNumber, "Error-Code: " & ErrNumber & " - Error-Description: " & ErrDescription Print#FileNumber, "In Function: " & FunctionName Close#FileNumber End Sub
Then in the functions/sub, that contain sensitive code (code which can crash, like saving something to a database, or validating User-Input)
vb Code:
Private Sub MySensitiveCodeSub() 'Dim some Variables here On Error Resume Next 'DON'T START ON ME ABOUT THIS! 'Execute sensitive Code here If Err.Number<>0 then 'Err.Number = 0 means: No Error occured Call ErrorHandler("MySensitiveCodeSub", Err.Number, Err.Description) Err.Clear 'Do something else, like Exit the Sub, give a message to the User, continue with your code, whatever else End If 'Execute other sensitive stuff End Sub
You could even improve my ErrorHandler-Function with a ParamArray Argument to send information about the values of the variables and so on.