Working with Exceptions
The MYOB Acumatica Framework provides you with a comprehensive set of exceptions that you may use for various development scenarios while you are implementing business logic on your MYOB Acumatica instance. All of these exceptions are derived from the PXException base class. This base class provides the localization of error messages, as well as a number of helper methods. For details, see PXException. For a list of all the available exceptions, see the Platform API Reference.
Here are some common development scenarios in which you should use the exceptions provided by the framework:
- Handling failed data validation: You throw an exception of the PXSetPropertyException type to interrupt an insert, update, or delete operation that the system performs on a data field if the validation criteria for this field is not met. This exception displays an error message next to the corresponding UI element of the data field. Alternatively, if you want to avoid interrupting the operation, you may do so by passing an instance of PXSetPropertyException to the RaiseExceptionHandling<>() method of the PXCache<> type. For details, see Data Validation: Validation of Field Values.
- Redirecting the user to a webpage: You throw an exception by using a descendent of the PXBaseRedirectException type to redirect a user from one webpage to another. The framework provides you with a number of exceptions that are derived from the PXBaseRedirectException base class, such as PXPopupRedirectException and PXRedirectWithReportException. All the exceptions derived from PXBaseRedirectException perform a redirection operation for specific contexts. For details, see Redirection to Webpages: General Information.
In some rare cases, you may need to write your own custom exceptions. For details, see Creating a Custom Exception.