When something goes wrong in your program it may be necessary to show an error message or a warning.
This example demonstrates the available options when dealing with errors:
In the event that something doesn't quite behave as expected you can call the command Error to display an error message on screen:
Error ( "something has broken" )
Warnings can be used when something may be amiss, but it's not quite critical to the running of the application. To display a warning use the command Warning. A warning will get displayed in the debug output of the IDE:
Warning ( "missing some data" )
When an error occurs, AGK can take one of three options - ignore it, report it and continue or report it and stop the program. This is controlled with the command SetErrorMode. The command takes one parameter with a value of 0 meaning errors are ignored, a value of 1 will report errors and allow the program to continue, and finally a value of 2 will report the error and then stop the program. The default value is 1. This line sets our program to ignore all errors:
SetErrorMode ( 0 )
This code will display an error, then a warning, followed by the error mode being set to 0 (so errors are ignored) and then attempting to display another error which will not be shown:
Error ( "something has broken" ) Warning ( "missing some data" )
SetErrorMode ( 0 )
Error ( "this error will not be shown" )
Not all applications will need to check for errors, but when it's necessary this extra care in your coding will be appreciated by your users.