Based on some observations about exceptions, I have explained an exception handling framework that I am intending to implement in future projects. Its features can be summarized as follows:

  • It is a three-tiered architecture with the Library layer, the Logic layer, and the Presentation layer.
  • Exceptions raised in the libraries used are converted to exceptions defined in the application.
  • Exceptions are divided into three categories, and they are defined as subclasses for RecoveredException, UnrecoveredException, and FatalError.
  • Messages stored in exception instances are used for debugging purposes and are not meant for showing on the UI.
  • Exception instances hold attributes that are used to compose messages on the UI.
  • Messages for debugging will be stored in the log.
  • Messages shown on the UI are generated in the Presentation layer using attributes in the exception. This is where localization happens. Input errors do not necessarily involve exceptions.

Implementation of exception handling and internationalization tend to be postponed until later in development. Since their implementation involves getting deep into the source code, it turns out to be quite some work if done late. I hope most of the readers find this article before they start coding. If not, they should start as soon as possible.

Contents

Background

Review of Exception Handling Basics

The Requirements

The Three-tiered Exception Handling Architecture

Summary