CHAPTER 1 - Introduction to X++
CHAPTER 2 - X++ Control Statements
CHAPTER 3 - Objects and Classes
CHAPTER 4: Accessing the Database
CHAPTER 5: Exception Handling
CHAPTER 6: Security for Developers
Lesson 2- Try and Catch Statements
Try and Catch Statements
Try statements signify the start of a block of code that you want to control with the X++ exception handling system. Any exceptions that are thrown in that block of code can be caught and handled in the associated Catch statements.
Catch statements come after the Try statement and define what code is executed when each exception is thrown. You do not have to define for every possible exception. However, each Try statement must have at least one . It is also possible to defines that is executed for any exception type. Try statements can be made within the scope of other Try statements. If a Catch statement is not defined for the exception being thrown by an inner Try statement, the code will step out to the next outer Try statement to attempt to find a matching for the exception. This will continue until a Catch statement is found, or there are no more outer Try statements.
Retry statements tell the system to go back to the Try statement and attempt to execute the code again. Any data that is loaded before the Try statement will remain as it is, but any data retrieved or modified after the Try statement will be refreshed.