Jump to content

Recommended Posts

I'm try to add error handle after autoit error ( I don't want the autoit error message show up )

My intention is to move the file, record the error script line and restart the script's .exe file due to an unexpected error while reading file's content

I tried to use the ObjEvent with AutoIt.Error, but not work

do I misunderstand how the AutoIt.Error work ?

'cause PIP I can't provide the original script, here is sample script with similar logic I tried ( $FT_Name unexpected error, content without @ char )

Global $errorFlow_Global = ObjEvent("AutoIt.Error", "error_Global")

Global $File = "C:\Desktop\ABC.txt"

Global $Name

; ==============================

$Name = Fun_Test()

ConsoleWrite("Name : " & $Name & @CRLF)

Exit

; ==============================

Func Fun_Test()

   Local $errorFlow_Local = ObjEvent("AutoIt.Error", "error_Local")

   Local $FT_Fle = $File, $FT_Content, $FT_Name

   _FileReadToArray($FT_Fle, $FT_Content)

   $FT_Name = StringSplit($FT_Content, "@")[1]

   Return $FT_Name

EndFunc

; ==============================

Func error_Global($eG_Info)

   ConsoleWrite("Global, error Line : " & $eG_Info.scriptline & @CRLF)

   FileMove($File, "C:\ABC", 1 + 8 )

   Run(@ComSpec & " /c timeout /t 3&&C:\Desktop\ABC.exe")

EndFunc

; ==============================

Func error_Local($eL_Info)

   ConsoleWrite("Local, error Line : " & $eL_Info.scriptline & @CRLF)

   FileMove($File, "C:\ABC", 1 + 8 )

   Run(@ComSpec & " /c timeout /t 3&&C:\Desktop\ABC.exe")

EndFunc

 

 

 

Link to comment
Share on other sites

Your script does not work as ObjEvent only handles Events from the given Object or COM errors.
To handle errors of an AutoIt function you have to check @error and @extended. The values of this macros are described in the help file for each function.
 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Posted (edited)

thanks for replay water, but not really understanding how to script with I needed (  sorry for my foolishness )

Could you please provide me with sample script references for understanding ?

and If script workable with my error handle flow, does any suggestions ?

many thanks again !! 

Edited by jimmy123j
Link to comment
Share on other sites

I wanted to tell you that you need to drop all ObjEvent code and use the macros @error and @extended to check for errors.
Like:

Global $File = "C:\Desktop\ABC.txt"
Global $Name

; ==============================

$Name = Fun_Test()
ConsoleWrite("Name : " & $Name & @CRLF)
Exit

; ==============================
Func Fun_Test()
   Local $FT_Fle = $File, $FT_Content, $FT_Name
   _FileReadToArray($FT_Fle, $FT_Content)
   If @error <> 0 Then Exit ConsoleWrite("Error returned by _FileReadToArray on line " & @ScriptLineNumber - 1 & @CRLF)
   $FT_Name = StringSplit($FT_Content, "@")[1]
   If @error <> 0 Then Exit ConsoleWrite("Error returned by _StringSplit on line " & @ScriptLineNumber - 1 & @CRLF)
   Return $FT_Name
EndFunc

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...