System Versus Application Exceptions

Exceptions can be further classified into either system exceptions or application exceptions. System exceptions are more serious in nature. These are typically low-level problems that aren’t related to the application logic and from which end users are not expected to recover. In many cases, system exceptions are unchecked, and your application isn’t supposed to catch them because they are either non-programming errors or are so severe that nothing can be done about them.

Application exceptions are errors that occur because of a violation of a business rule or some other condition in the application logic. For example, you might throw an application exception when a user attempts to log in to the application but the account has been locked. This isn’t a catastrophic error, but it is a problem that needs to be reported and handled.

Within Struts applications (and web applications in general), there are essentially two approaches you can take when an exception occurs. If the exception is an application exception from which the end user may be able to recover, you typically want to return control back to the input page and display a user-friendly statement of the problem and some action that can be taken to resolve it. Continuing with the locked account example, you could throw an AccountLockedException back to the action class, which would forward control back to the login page and inform the user that the account is locked.

If the thrown exception ...

Get Programming Jakarta Struts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.