Clarifying Error and OSError object
Posted: 08 Feb 2023, 18:55
In this post, I explained that the documentation about OSError was unclear to me (at least with my background). Maybe this could be explained with an example.
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)