Here is an example using a read-only file to test the error message.The following subclasses of Error are predefined:
MemoryError: A memory allocation failed.
OSError: An internal function call to a Win32 function failed....
Code: Select all
Loop ; wait until a file can be written, or abort after 1 second
{
Try
FileAppend(A_Now . "`n", A_ScriptDir . "\read-only.txt")
catch Error as err ; err contains the predefined OSError object
Sleep(20)
else
Break
}
until (A_Index > 50)
if IsObject(err)
MsgBox(err.Message)