From D Wiki
Revision as of 06:37, 1 April 2013 by Kyllingstad (talk | contribs) (Created page with "'''<span style="color: red">This DIP is currently under construction. Please come back later.</span>''' {| class="wikitable" !Title: !'''A new exception hierarchy''' |- |DIP...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This DIP is currently under construction. Please come back later.

Title: A new exception hierarchy
DIP: 33
Version: 1
Status: Draft
Created: 2013-04-01
Last Modified: 2013-04-01
Author: Lars T. Kyllingstad


This is a proposal for a new exception hierarchy for Druntime and Phobos.



The following is an outline of the exceptions in the hierarchy, and how they are related to each other. Deeper levels are subclasses of those above.

  • Throwable
    • Error
      • AssertError
      • InvalidArgumentError
      • RangeError
    • Exception
      • ConversionException
      • Exception
      • EncodingException
      • FilesystemException
      • IOException
        • NetworkException
      • ParseException
        • DocParseException
      • ProcessException
      • SystemException
        • ErrnoException
        • WinAPIException
      • ThreadException
    • OutOfMemory

Top-level classes


class Error : Throwable { }

Error and its subclasses are used to signal programming errors. If an Error is thrown, it means that there is something wrong with how the program is constructed. Examples include array index out of bounds, invalid function arguments, etc. Errors can always be avoided by design.


class Exception : Throwable { }

Exception and its descendants are used to signal normal runtime errors. These are exceptional circumstances that the programmer cannot be expected to avoid by design. Examples include file not found, problems with parsing a document, system errors, etc.


class OutOfMemory : Throwable { }

This exception is thrown on an attempt to allocate more memory than what is currently available for the program. Strictly speaking, this is not an Error, as the programmer cannot reasonably be expected to check memory availability before each allocation. However, is not desirable to catch it along with normal Exceptions either, as an OOM condition requires special treatment. Therefore, this DIP places OutOfMemory at the top level of the hierarchy.


This document has been placed in the Public Domain.