AutoIt Version: 3.3.10.2+ UDF Version: 2.0 Description: This library allows to register function for AutoIt critical errors. Usually it's syntax errors, or array-related errors. By default the UDF shows custom debug dialog, although it is not possible to perform any real debugging, but we can for example display the error message, restart application, send bug report, or just close the application. Example #1 - Displaying built-in dialog when error is received: #NoTrayIcon
#AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileClose(FileOpen('%scriptdir%\OAER_RAW_SRC.tmp', 2))"
#AutoIt3Wrapper_Run_After=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileDelete('%scriptdir%\OAER_RAW_SRC.tmp')"
#include <GUIConstantsEx.au3>
#include 'OnAutoItErrorRegister.au3'
_OnAutoItErrorRegister('', '', 'My App Error', False, False)
GUICreate('OnAutoItErrorRegister Example', 350, 200)
GUICtrlCreateLabel('This script is just an example.' & @CRLF & @CRLF & 'It will produce a syntax error in', 25, 40, 300, 50)
GUICtrlCreateLabel('5', 185, 50, 50, 40)
GUICtrlSetColor(-1, 0xF20000)
GUICtrlSetFont(-1, 30, 800, 0, 'Tahoma')
GUICtrlCreateLabel('seconds.', 220, 67, 300, 50)
GUICtrlCreateLabel('The result shown as a CUSTOM error message, you can change it!', 25, 120, 350, 20)
$iUnRegister_Bttn = GUICtrlCreateButton('UnRegister AutoItError handler', 25, 140, 200, 22)
GUICtrlCreateLabel('Copyright jennico, G.Sandler (MrCreatoR) © 2008 - 2015', 25, 170, 350, 80)
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetFont(-1, 8.5, 800, 6)
GUISetState()
Dim $iTimer
For $i = 3 To 1 Step -1
GUICtrlSetData(4, $i)
$iTimer = TimerInit()
While TimerDiff($iTimer) < 1000
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $iUnRegister_Bttn
_OnAutoItErrorUnRegister()
EndSwitch
WEnd
Next
;We deliberately make a syntax mistake and call the error!
If Random(1, 5, 1) = 3 Then
MsgBox(0, '', )
Else
_NotExistingFunc()
EndIf Example #2 - Call user defined function when receiving error (script restart): #NoTrayIcon
#AutoIt3Wrapper_Run_AU3Check=n
;!!! This must be used to ensure that raw source file is generated before compilation (because $bSetErrLine is True)
#AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe "%in%" /BC_Strip
#AutoIt3Wrapper_Run_After=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileDelete('%scriptdir%\OAER_RAW_SRC.tmp')"
#pragma compile(Stripper, False)
#include 'OnAutoItErrorRegister.au3'
_OnAutoItErrorRegister('_MyErrorHandler', '', '', False, True)
;We deliberately make an array bounding error and call the error!
Dim $aArr[1]
MsgBox(0, '', $aArr[1])
Func _MyErrorHandler($sScriptPath, $iScriptLine, $sErrDesc, $vParams, $hBitmap) ;Restart the application
Local $sMessage = StringFormat('SCRIPT FILE:\n%s\n\nSCRIPT ERROR LINE:\n%s\n\nERROR DESCRIPTION:\n%s', $sScriptPath, $iScriptLine, $sErrDesc)
If StringInStr($CmdLineRaw, '/ErrorStdOut') Then
If FileExists(@WindowsDir & "\Media\chord.wav") Then
SoundPlay(@WindowsDir & "\Media\chord.wav")
Else
DllCall('user32.dll', 'int', 'MessageBeep', 'int', 0x00000010)
EndIf
EndIf
If MsgBox(BitOR($MB_SYSTEMMODAL, $MB_YESNO), 'Crash recieved!', 'Restart application?' & @CRLF & @CRLF & $sMessage) <> 6 Then
Return
EndIf
Local $sRunLine = @AutoItExe & ' "' & @ScriptFullPath & '"'
If @Compiled Then
$sRunLine = @ScriptFullPath
EndIf
Run($sRunLine, @ScriptDir)
EndFunc Download: OnAutoItErrorRegister.zip (Counter: ) Screenshot: ChangeLog: Initial idea by jennico: Author(s): G.Sandler (MrCreatoR), jennico Notes: The UDF can not handle crashes that triggered by memory leaks, such as DllCall crashes, "Recursion level has been exceeded..." (when using hook method ($bUseStdOut = False)).When using StdOut method ($bUseStdOut = True), CUI not supported, and additional process executed to allow monitor for errors.After using _OnAutoItErrorUnRegister when $bUseStdOut = True, standard AutoIt error message will not be displayed on following syntax error.To use the "Send bug report" feature, there is need to fill related parameters (variables) under the «User Variables» section in UDF file (check the comments of these variables), or just build your own user function.[If $bSetErrLine is True...] Script must be executed before compilation (after any change in it), or use '#AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe "%in%" /BC_Strip' in your main script. Do NOT use Au3Stripper when compiling the main script if you want correct error line detection for compiled script. To get correct code line for compiled script, the script is transformed to raw source (merging includes) and FileInstall'ed when it's needed (on error), therefore, the script is available in temp dir for few moments (when error is triggered), although it's crypted, but developer should ensure that his script is more protected. [If $bSetErrLine is False...] Use supplied GetErrLineCode.au3 to get proper error line code by line number from error that was triggered in compiled script.