statement. The Throw statement explicitly declares what type of exception is
thrown to the Catch list. If the Try statement does not include a Catch list, the
exception moves to the next Try statement.
In the following example, the code throws an error exception and at the same
time, an error message is placed in the Infolog (this is a feature of the error
function in X++). When the error exception is caught, a second error message is
placed in the Infolog. Both error messages are then reported to the user.
1 2 3 4 5 6 7 8 9 10 11 12 | CustTable custTable; try { select custTable where custTable.accountNum == "1019"; if (!custTable.RecId) throw error("Customer does not exist"); } catch (exception::error) { error ("Process was aborted"); } |
The previous lesson discussed the transaction tracking system and the ttsabortstatement. This statement ends the transaction and returns the data to its state at
the corresponding ttsbegin statement. When the system throws an exception,ttsabort is called automatically, and so does not have to be called in a Catch
statement. Using the throw and error statements together in the previously
mentioned format, you effectively abort a transaction, jump to the Catch list to
handle the error exception, and send an error message to the user in one line.
Best Regards,
Hossein Karimi
No comments:
Post a Comment