Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::Exception Class Reference

Base class for all MITK exceptions. More...

#include <mitkException.h>

Inheritance diagram for mitk::Exception:
Collaboration diagram for mitk::Exception:

Classes

struct  ReThrowData
 Internal storage for a single rethrow record. More...
 

Public Member Functions

 Exception (const char *file, unsigned int lineNumber=0, const char *desc="None", const char *loc="Unknown")
 Construct an exception with source location and description. More...
 
 ~Exception () override throw ()
 Destructor. More...
 
virtual const char * GetClassName () const
 
void AddRethrowData (const char *file, unsigned int lineNumber, const char *message)
 Record additional rethrow context for this exception. More...
 
int GetNumberOfRethrows ()
 Return the number of times this exception has been rethrown. More...
 
void GetRethrowData (int rethrowNumber, std::string &file, int &line, std::string &message)
 Retrieve the rethrow context for a specific rethrow. More...
 
template<class T >
Exception & operator<< (const T &data)
 Append data to the exception description via the stream operator. More...
 
template<class T >
Exception & operator<< (T &data)
 Append non-const data to the exception description via the stream operator. More...
 
Exception & operator<< (std::ostream &(*func)(std::ostream &))
 Append a stream manipulator (e.g. std::endl) to the exception description. More...
 

Protected Attributes

std::vector< ReThrowData > m_RethrowData
 List of recorded rethrow contexts. More...
 

Detailed Description

Base class for all MITK exceptions.

Extends itk::ExceptionObject with support for rethrow tracking and stream-style message composition. Do not instantiate this class directly; use the exception macros defined in mitkExceptionMacro.h instead.

Simple usage:

mitkThrow() << "optional exception message";
#define mitkThrow()
Throw a generic mitk::Exception with source location information.

To define a specialized exception, inherit from this class and use the mitkExceptionClassMacro:

class MyException : public mitk::Exception
{
public:
};
Base class for all MITK exceptions.
Definition: mitkException.h:53
#define mitkExceptionClassMacro(ClassName, SuperClassName)
Convenience macro for defining MITK exception subclasses.

Throw specialized exceptions with:

mitkThrowException(MyException) << "optional exception message";
#define mitkThrowException(classname)
Throw a specialized exception derived from mitk::Exception.
See also
mitkThrow, mitkReThrow, mitkThrowException, mitkExceptionClassMacro

Definition at line 52 of file mitkException.h.

Constructor & Destructor Documentation

◆ Exception()

mitk::Exception::Exception ( const char *  file,
unsigned int  lineNumber = 0,
const char *  desc = "None",
const char *  loc = "Unknown" 
)
inline

Construct an exception with source location and description.

Parameters
[in]fileSource file where the exception was thrown.
[in]lineNumberLine number in the source file.
[in]descHuman-readable description of the error.
[in]locLocation string (typically the function name via ITK_LOCATION).

Definition at line 62 of file mitkException.h.

◆ ~Exception()

mitk::Exception::~Exception ( )
throw (
)
inlineoverride

Destructor.

Definition at line 68 of file mitkException.h.

Member Function Documentation

◆ AddRethrowData()

void mitk::Exception::AddRethrowData ( const char *  file,
unsigned int  lineNumber,
const char *  message 
)

Record additional rethrow context for this exception.

Each call appends a new rethrow record. Use the mitkReThrow macro instead of calling this directly.

Parameters
[in]fileSource file where the rethrow occurred.
[in]lineNumberLine number of the rethrow.
[in]messageDescriptive message for the rethrow.
See also
mitkReThrow, GetNumberOfRethrows, GetRethrowData

◆ GetClassName()

virtual const char* mitk::Exception::GetClassName ( ) const
virtual

◆ GetNumberOfRethrows()

int mitk::Exception::GetNumberOfRethrows ( )

Return the number of times this exception has been rethrown.

Returns
The rethrow count (0 if the exception was never rethrown).

◆ GetRethrowData()

void mitk::Exception::GetRethrowData ( int  rethrowNumber,
std::string &  file,
int &  line,
std::string &  message 
)

Retrieve the rethrow context for a specific rethrow.

If rethrowNumber is out of range (negative or >= GetNumberOfRethrows()), the output parameters are set to empty/zero values.

Parameters
[in]rethrowNumberZero-based index of the rethrow to query.
[out]fileFilled with the source file of the specified rethrow.
[out]lineFilled with the line number of the specified rethrow.
[out]messageFilled with the message of the specified rethrow.
See also
AddRethrowData, GetNumberOfRethrows

◆ operator<<() [1/3]

template<class T >
Exception& mitk::Exception::operator<< ( const T &  data)
inline

Append data to the exception description via the stream operator.

Template Parameters
TType of the data to append (must be streamable to std::ostream).
Parameters
[in]dataThe data to append to the description string.
Returns
Reference to this exception for chaining.

Definition at line 113 of file mitkException.h.

◆ operator<<() [2/3]

Exception& mitk::Exception::operator<< ( std::ostream &(*)(std::ostream &)  func)
inline

Append a stream manipulator (e.g. std::endl) to the exception description.

Parameters
[in]funcA stream manipulator function pointer.
Returns
Reference to this exception for chaining.

Definition at line 141 of file mitkException.h.

◆ operator<<() [3/3]

template<class T >
Exception& mitk::Exception::operator<< ( T &  data)
inline

Append non-const data to the exception description via the stream operator.

Template Parameters
TType of the data to append (must be streamable to std::ostream).
Parameters
[in]dataThe data to append to the description string.
Returns
Reference to this exception for chaining.

Definition at line 128 of file mitkException.h.

Member Data Documentation

◆ m_RethrowData

std::vector<ReThrowData> mitk::Exception::m_RethrowData
protected

List of recorded rethrow contexts.

Definition at line 159 of file mitkException.h.


The documentation for this class was generated from the following file: