Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkExceptionMacro.h File Reference
#include <mitkException.h>
#include <itkMacro.h>
#include <mitkLog.h>
#include <sstream>

Go to the source code of this file.

Macros

#define mitkThrow()
 Throw a generic mitk::Exception with source location information. More...
 
#define mitkReThrow(mitkexception)
 Rethrow an existing mitk::Exception while recording rethrow context. More...
 
#define mitkThrowException(classname)
 Throw a specialized exception derived from mitk::Exception. More...
 
#define mitkExceptionClassMacro(ClassName, SuperClassName)
 Convenience macro for defining MITK exception subclasses. More...
 

Macro Definition Documentation

◆ mitkExceptionClassMacro

#define mitkExceptionClassMacro (   ClassName,
  SuperClassName 
)

Convenience macro for defining MITK exception subclasses.

Generates a constructor compatible with the exception macros and provides stream operators and ITK RTTI support. All MITK exception classes should derive from mitk::Exception and use this macro in their public section.

Parameters
ClassNameName of the new exception class.
SuperClassNameName of the parent exception class (typically mitk::Exception).
See also
mitk::Exception, mitkThrowException

Definition at line 88 of file mitkExceptionMacro.h.

◆ mitkReThrow

#define mitkReThrow (   mitkexception)

Rethrow an existing mitk::Exception while recording rethrow context.

The file and line of the rethrow site are stored in the exception so that the full rethrow chain can be inspected via mitk::Exception::GetNumberOfRethrows() and mitk::Exception::GetRethrowData().

Example:

try
{
// some code that throws an exception
}
catch (mitk::Exception &e)
{
mitkReThrow(e) << "Message appended to the exception (optional)";
}
Base class for all MITK exceptions.
Definition: mitkException.h:53
#define mitkReThrow(mitkexception)
Rethrow an existing mitk::Exception while recording rethrow context.
Parameters
mitkexceptionThe mitk::Exception (or derived) object to rethrow.
See also
mitk::Exception::AddRethrowData

Definition at line 56 of file mitkExceptionMacro.h.

◆ mitkThrow

#define mitkThrow ( )

Throw a generic mitk::Exception with source location information.

Use the stream operator to append a human-readable message:

mitkThrow() << "this is error info";
#define mitkThrow()
Throw a generic mitk::Exception with source location information.
See also
mitk::Exception, mitkReThrow, mitkThrowException

Definition at line 31 of file mitkExceptionMacro.h.

◆ mitkThrowException

#define mitkThrowException (   classname)

Throw a specialized exception derived from mitk::Exception.

The classname must be a class that inherits from mitk::Exception and uses the mitkExceptionClassMacro in its definition. Use the stream operator to append an error message:

mitkThrowException(MySpecializedException) << "this is error info";
#define mitkThrowException(classname)
Throw a specialized exception derived from mitk::Exception.
Parameters
classnameFully qualified class name of the exception to throw.
See also
mitk::Exception, mitkExceptionClassMacro

Definition at line 74 of file mitkExceptionMacro.h.