Jump to content

All errors handling


gahhon
 Share

Recommended Posts

_Metro_SplashTextScreen(1, "", $iMsg)
AdlibRegister("_Metro_LoopInProgress")
DirRemove($DIR_WA_FOLDER, 1)
Local $iCopy = _WinAPI_ShellFileOperation($CUR_WA_FOLDER, $DIR_WA_FOLDER, $FO_COPY, BitOr($FOF_SIMPLEPROGRESS, $FOF_NOCONFIRMMKDIR))
AdlibUnRegister("_Metro_LoopInProgress")
_Metro_SplashTextScree
If @error Then
    _Metro_MsgBox(0, "", $iCopy)
    _FileWriteLog($LOG_INSTALLATION, "Error: " & $iCopy)
Else
    _Metro_MsgBox(0, "", "Application is up to date!")
    _FileWriteLog($LOG_INSTALLATION, "Debug: Application is up to date.")
EndIf

According to the help file of _WinAPI_ShellFileOperation there are a lot of failure and error code. But how can I handle all of them and display corresponding error message based on the help file?

The incident is like this:
I'll lock the folder with permission, so when I execute the _WinAPI_ShellFileOperation to copy and overwrite the folder contents, it popped me an error message saying that permission issue to caused I can't access the folder and overwrite the contents.

image.png.43ff48a5171701909761ca3cbf70f25e.png

Then I clicked Cancel button, and my AutoIT application exit immediately and it's not execute the function _Metro_MsgBox(0, "", $iCopy) to display the message.

 

Anyway, I did also tried the code below, the it still display "Application is up to date!"
According to the help file, 120 - Security settings denied access to the source.

If @error = 120 Then
    _Metro_MsgBox(0, "", $iCopy)
    _FileWriteLog($LOG_INSTALLATION, "Error: " & $iCopy)
Else
    _Metro_MsgBox(0, "", "Application is up to date!")
    _FileWriteLog($LOG_INSTALLATION, "Debug: Application is up to date.")
EndIf

 

Link to comment
Share on other sites

You could try adding @error to the log, or to a consolewrite to see what number it gives, maybe it's not 120.

You could also do something like

If $icopy = @error Then

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

9 minutes ago, careca said:

You could try adding @error to the log, or to a consolewrite to see what number it gives, maybe it's not 120.

You could also do something like

If $icopy = @error Then

 

I have no idea why can't use ConsoleWrite because it don't print anything. But I try display it via _Metro_MsgBox and it showed "10"
Then I tried If @error = 10 Then display the corresponding error message, but it still jump to "Application is up to date!"

Local $iCopy = _WinAPI_ShellFileOperation($CUR_WA_FOLDER, $DIR_WA_FOLDER, $FO_COPY, BitOr($FOF_SIMPLEPROGRESS, $FOF_NOCONFIRMMKDIR))
_Metro_MsgBox(0, "", @error & ' - ' & $iCopy)

image.png.86cbce7eac62ee54289f79f5fe251338.png

 

Edited by gahhon
Link to comment
Share on other sites

Hi gahhon,
Don't forget that @error is reassigned to 0 each time a new function is encountered (help file, topic SetError)
So trying to reuse @error a few lines after it happened often fails. Just keep it in a variable immediately after it occurs or you'll experience this kind of issue :
 

#include <MsgBoxConstants.au3>

Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt")
If @error Then
   MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 1
   MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 0
Endif

 

Link to comment
Share on other sites

11 minutes ago, pixelsearch said:

Hi gahhon,
Don't forget that @error is reassigned to 0 each time a new function is encountered (help file, topic SetError)
So trying to reuse @error a few lines after it happened often fails. Just keep it in a variable immediately after it occurs or you'll experience this kind of issue :
 

#include <MsgBoxConstants.au3>

Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt")
If @error Then
   MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 1
   MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 0
Endif

 

So you are saying that I should store the error code and the error message when after executed the particular function?

All right, but I do have one question that error is actually don't declare in the help file, so I don't get any error message from the help file.
It is normal? So that I can declare my own error message?

Link to comment
Share on other sites

1 hour ago, gahhon said:

I have no idea why can't use ConsoleWrite because it don't print anything.

Are you using #requireadmin?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

There you go, comment it.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

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...