Although I wrote that exceptions will be converted to messages on the UI, most of the messages we see often should not involve exceptions. This is partly because errors in user input should be detected (validated) at the time of entry, not while the request is being processed. These errors don’t need to involve exceptions.Having said that, there are cases where exceptions do lead to messages on the UI. I will explain a little on how this can be done.

Before that, I need to remind you of two modes of messages and two ways of handling errors.

  • Modal: A window (dialog box) is shown to display the message, and the user cannot interact with the software unless the window is closed.
  • Modeless: A window is shown to display the message, which may be hidden by other windows. This allows the user to interact with the software without closing the window with the message.
  • Synchronous: The thread is stopped until the message window is closed.
  • Asynchronous: The thread continues running while the message window is open.

These are concepts that are similar, but different in what is stopped. One stops the user. The other stops the thread. Care should be taken when choosing how to deliver a message. If we use modal or synchronous messages unnecessarily, we would end up with a frustrating piece of software.

There are also different kinds of users to which a message would be directed.

  • Immediate user: The user interacting with the software.
  • Administrator: The user who is responsible for maintenance of the software. Usually, it is enough to log any kind of exception, but sometimes, if the exception is serious, an alert must be sent to the administrator. The alert is usually not made through the UI (maybe by email or SMS), because the admin is not always interacting directly with the software. The administrator will become the immediate user, if that person starts interacting with the software.
  • Others: There may be other kinds of users depending on the software.

Once you choose the method, it should be obvious how to do the programming. It should very rarely be the case that a raw exception message is shown by throwing the exception directly to the UI framework. In other words, the Presentation layer has the work of converting the exceptions that it caught into the message of choice.

Contents

Background

Review of Exception Handling Basics

The Requirements

The Three-tiered Exception Handling Architecture

Summary