The throw keyword is used to throw an exception enum value. For example, the statement throw Exception::error; would be used to throw an error exception. We recommend that you use the Global::error method instead of the Exception::error. The Global::error can write a message to the Infolog when an error exception is thrown and convert a label automatically into text. You can also write the Global::error(“Error message.”) as error(“Error message.”).
The try…catch keywords are used to process a thrown exception through the catch. The code is run in the try code block. If an error is thrown, the code will jump to run the catch code blocks sequentially to see if the thrown error is specified to handle the error. It is a common practice to have the first catch statement handle the Exception::Error enum value and leave one catch blank to catch any unspecified error. The Finally keyword can be used with the Try…catch statement. The code in the finally code block will run when the code leaves the try block either normally or because of an error. See the following code example.
The retry keyword can only be written in a catch block. This causes the code to jump back to the first line in the try code block. A retry should be used when the issue can be fixed through code. The retry gives the code an additional chance to succeed and will display an Infolog when the try block started to run. You must make sure that the retry statement does not cause an infinite loop. We recommend that you include a variable in the try block to test if you are in an infinite loop.
You can throw several error exceptions: