Try/Catch instead of ErrorLevel
Posted: 30 May 2018, 10:05
https://lexikos.github.io/v2/docs/comma ... .htm#ex_el
i tried running that, but i couldnt understand when the catch block was supposed to be triggered. When ErrorLevel != 0 ? When A_LastError != 0 ?
i stripped it down to this:
the 1st time its run, it will copy text.txt(the file existing is a given) to the folder. ErrorLevel = 0, LastError = 0, catch isnt triggered as expected
the 2nd time its run, it will fail to copy the file(overwrite flag omitted, disabled by default), ErrorLevel = 1, LastError = 80 ERROR_FILE_EXISTS, yet catch still isnt being triggered
so what was supposed to happen here? it works when handling messed up COM objects, but thats because they throw runtime exceptions
i tried running that, but i couldnt understand when the catch block was supposed to be triggered. When ErrorLevel != 0 ? When A_LastError != 0 ?
i stripped it down to this:
Code: Select all
try
{
FileCopy("D:\test.txt", "D:\Backup")
}
catch
{
MsgBox("There was a problem while backing the files up!",, 16)
ExitApp
}
MsgBox(Format("ErrorLevel: {}`nLastError: {}", ErrorLevel, A_LastError))
the 2nd time its run, it will fail to copy the file(overwrite flag omitted, disabled by default), ErrorLevel = 1, LastError = 80 ERROR_FILE_EXISTS, yet catch still isnt being triggered
so what was supposed to happen here? it works when handling messed up COM objects, but thats because they throw runtime exceptions