![]() ![]() Executed no matter how the try block exits. As a best practice, the try block should include a variable that you can test to find out whether you're in a loop. You must make sure that your retry statements don't cause an infinite loop. The retry statement erases all messages that have been written to the Infolog since program control entered the try block. The retry statement gives the code in the try block another opportunity to succeed. ![]() The retry statement is used when the cause of the exception can be fixed by the code in the catch block. The retry statement causes control to jump up to the first line of code in the associated try block. The retry statement can be written only in a catch block. The statements in the finally clause are executed when control leaves the try block, either normally or through an exception. The semantics of a finally clause are the same as they are in C#. catch blocks.Īn optional finally clause can be included in try. This strategy is appropriate for the outermost try. In this case, the last catch statement handles all exceptions that aren't handled by any earlier catch statement. One strategy is to have the last catch statement leave the exception type unspecified. It's a common practice to have the first catch statement handle the Exception::Error enum value. The catch statements are processed in the same sequence as they appear in the code. If the catch list has no block that specifies the exception, the system passes the exception to the catch list of the next-innermost try block. If a catch block is found that handles the kind of exception that is being thrown, program control jumps to that catch block. When an exception is thrown, it's first processed through the catch list of the innermost try block. Try, catch, finally, and retry statements The original exception, exception message and its context such as call stack will be rethrown and be available to any catch statements in calling code. In such a case, throw will behave like the rethrow statement in C#. throw new InvalidOperationException("This function is not allowed") Īlso in Platform update 31 or later, the throw keyword can be used by itself inside a catch block. In Platform update 31 or later versions, the throw keyword can be used to throw. For example, the Global::error method can be called like this. throw static methods on the Global class can be called without the Global:: prefix. This functionality helps you write code that can be localized more easily. The Global::error method can automatically convert a label into the corresponding text. throw Global::error("The parameter value is invalid.") Instead of throwing an enum value, a best practice is to use the output of the Global::error method as the operand for throw. For example, the following statement throws an error exception. You use the throw keyword to throw an Exception enum value. You don't necessarily have to know the location of the catch block that will receive control when the exception is thrown. In this case, the method can throw an exception to immediately transfer control to a catch code block that contains logic for handling this error situation. For example, your method might receive an input parameter value that isn't valid. The Global::error method is often the best way to write diagnostic information to the Infolog. A common practice is to write diagnostic information to the Infolog before the exception is thrown. One exception that is often thrown is the Exception::error enum value. NET's System.Exception class or a derived class. An exception is represented by a value of the Exception enumeration, or an instance of. The instruction where program execution resumes is determined by try.catch blocks and the type of exception that is thrown. catch, finally, and retry statements to generate and handle exceptions.Īn exception is a regulated jump away from the sequence of program execution. You handle errors by using the throw, try. ![]() This article describes exception handling in X++. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |