Class Exception

Inheritance Relationships

Base Type

  • public exception

Class Documentation

class Exception : public exception

Provides consistent interface for LSST exceptions.

All exceptions defined by the LSST Stack are derived from this class. Code should not throw or catch Exception directly, but should instead be written in terms of the appropriate subclasses (e.g., catch RuntimeError to handle all unknown errors).

In Python, this exception inherits from builtins.Exception.

Public Functions

Exception(char const *file, int line, char const *func, std::string const &message)

Standard constructor, intended for C++ use via the LSST_EXCEPT() macro.

Parameters
  • [in] file: Filename (automatically passed in by macro).

  • [in] line: Line number (automatically passed in by macro).

  • [in] func: Function name (automatically passed in by macro).

  • [in] message: Informational string attached to exception.

Exception(std::string const &message)

Message-only constructor, intended for use from Python only.

While this constructor can be called from C++, it’s better to use the LSST_EXCEPT macro there, which stores file/line/function information as well. In Python, however, that information is stored outside the exception, so we don’t want to duplicate it, and hence this constructor is invoked instead.

Parameters
  • [in] message: Informational string attached to exception.

virtual ~Exception(void)
void addMessage(char const *file, int line, char const *func, std::string const &message)

Add a tracepoint and a message to an exception before rethrowing it (access via LSST_EXCEPT_ADD).

Parameters
  • [in] file: Filename (automatically passed in by macro).

  • [in] line: Line number (automatically passed in by macro).

  • [in] func: Function name (automatically passed in by macro).

  • [in] message: Additional message to associate with this rethrow.

Traceback const &getTraceback(void) const

Retrieve the list of tracepoints associated with an exception.

virtual std::ostream &addToStream(std::ostream &stream) const

Add a text representation of this exception, including its traceback with messages, to a stream.

Return

Reference to the output stream after adding the text.

Parameters
  • [in] stream: Reference to an output stream.

virtual char const *what(void) const

Return a character string summarizing this exception.

This combines all the messages added to the exception, but not the type or traceback (use the stream operator to get this more detailed information).

Not allowed to throw any exceptions.

Return

String representation; does not need to be freed/deleted.

virtual char const *getType(void) const

Return the fully-specified C++ type of a pointer to the exception. This is overridden by derived classes (automatically if the LSST_EXCEPTION_TYPE macro is used). It is used by the Python interface.

Return

String with the C++ type; does not need to be freed/deleted.

virtual Exception *clone(void) const

Return a copy of the exception as an Exception pointer. Can be overridden by derived classes that add data or methods.

Return

Pointer to a copy of the exception.