MONITOR is a way to perform any set of instructions and then catch any eventual errors.
Useful when you know there is a risk of an error and you don’t want to blow up the program in the users face.
It’s a way of performing a “try-catch” sequence. Try something and if it didn’t work, catch the error and do something else.
It consists of 3 main elements:
- monitor – States the beginning of the monitor group.
- on-error – States that you catch any errors and allows you to write code to be run in the event of an error.
- endmon – States the end of the monitor scope.
Example:
1 2 3 4 5 6 7 8 9 10 |
dcl-s counter int(5) inz; counter = *hival; monitor; // You can add as many lines of code you want here... counter += 3; // Try this on-error; counter = 1234; // If an error occurred, just set the value to 1234 endmon; |