Have questions regarding how error handling of instructions can/should be handled.
If I use the instruction PixelGetColor.
What different problems can arise?
The Error information for this instruction is ("An OSError is thrown on failure.")
When the link, which leads to the Error information, is opened OSError information I get more confused.
What can go wrong with eg. PixelSearch?
Can the error message be tested? (How?)
Error handling - ahk-v2
Re: Error handling - ahk-v2
It is very rare that the operating system throws errors with certain functions but I could envision PixelGetColor throwing an error if you pass invalid parameters or the operating system cannot access the "Screen information" so to speak. Keep in mind that I am oversimplifying here.
Most of the time the only thing you have to do is catch the error and look at A_LastError to know what the actual issue might be, like so:
You might want to log it to a file or depending on the error try to solve it.
an example of a NON OS Error might be this:
Notice that in this situation the error was not raised by the operating system so you will not get an OS_Error but instead a different type of error.
If you want to know a little bit more about error handling and what the different types of error objects you could get then suggest reading the Error help file.
Most of the time the only thing you have to do is catch the error and look at A_LastError to know what the actual issue might be, like so:
Code: Select all
Try color := PixelGetColor(100, 100)
Catch
MsgBox A_LastError
an example of a NON OS Error might be this:
Code: Select all
Try color := PixelGetColor("a string here", 100)
Catch Error as err
MsgBox err.what "`n" err.message
If you want to know a little bit more about error handling and what the different types of error objects you could get then suggest reading the Error help file.
Projects:
AHK-ToolKit
AHK-ToolKit