From SCIRun Documentation Wiki
Jump to navigation Jump to search

SCIRun Exceptions

This section explains SCIRun exceptions.


The Exceptions directory contains common exceptions and the Exception base class. Developers can create new exception classes, and these will need to be in other directories if they depend on other data structures outside of the Exception dir.

All exceptions in SCIRun are derived from the SCIRun::Exception base class. All derived classes implement a message method and a type method. The type method just returns a string (const char* actually) that indicates the classname of the exception. The message returns a human readable string that can be printed out when the exception is caught.

This directory also contains some general exceptions used throughout SCIRun.

  • AssertionFailed - thrown when an assertion fails.
  • ArrayIndexOutOfBounds - thrown to indicate a failed bounds check.
  • DimensionMismatch - thrown to indicate dimensionality differences.
  • FileNotFound - thrown when a file is not found.
  • InternalError - thrown when an internal error occurs.

Programming with SCIRun Exceptions

A developer is likely to use this code from within written modules as well as within new datatypes.

A couple development specific hints follow.

All exception classes must implement a copy constructor (for some compilers).

On the SGI, the exception classes will give you a stacktrace when they are caught (uses -lexc).

Exceptions in SCIRun, are only to be used for exceptional cases. General error handling should use another mechanism. Exceptions are expensive, and as such should only be used in cases that warrant it. One of the most common uses in this directory are ASSERT, and ASSERTFAIL.


This is used to verify that some condition is true before continuing. if the expression geven evaluates to false, the exception is thrown, which will eventually abort scirun.

This macro expands to nothing in an optimized build.

myClass *p = get_my_class();
ASSERT(p != 0);


This is used to abort with a nice message when something is wrong.

This macro expands to nothing in an optimized build.

switch(var) {
  case NICE:
  case EVEN_NICER:
    ASSERTFAIL("Unknown case, what happened?");

Go back to Documentation:SCIRun:DevManual