diff --git a/Core/Documentation/Doxygen/Concepts/Concepts.dox b/Core/Documentation/Doxygen/Concepts/Concepts.dox index e2477919d5..4caf8cec74 100644 --- a/Core/Documentation/Doxygen/Concepts/Concepts.dox +++ b/Core/Documentation/Doxygen/Concepts/Concepts.dox @@ -1,15 +1,17 @@ /** \page Concepts MITK concepts The following items describe some issues about MITK on a more abstract level. If you want to start using MITK, you also want to see \ref Development -\li \subpage GeometryOverviewPage -\li \subpage InteractionPage \li \subpage OverviewPage -\li \subpage MicroServices_Overview -\li \subpage PropertiesPage \li \subpage QVTKRendering +\li \subpage InteractionPage +\li \subpage ExceptionPage +\li \subpage LoggingPage +\li \subpage PropertiesPage +\li \subpage GeometryOverviewPage +\li \subpage MicroServices_Overview \li \subpage RenderingTests */ diff --git a/Core/Documentation/Doxygen/Concepts/Exceptions.dox b/Core/Documentation/Doxygen/Concepts/Exceptions.dox index f9d73bd9cc..f8d2298d27 100644 --- a/Core/Documentation/Doxygen/Concepts/Exceptions.dox +++ b/Core/Documentation/Doxygen/Concepts/Exceptions.dox @@ -1,23 +1,46 @@ namespace mitk{ /** -\page ExceptionPage Exception Handling Concept +\page ExceptionPage Error Handling and Exception Concept -Available sections: +\ref ExceptionHandling "General Exception Handling" +\ref SpecializedExceptionHandling "Defining and Using more Specialized Exceptions" --# \ref Sec1 "Section 1" --# \ref Sec2 "Section 2" +\section ExceptionHandling General Exception Handling -\section Sec1 Section 1 +In MITK, errors during program execution are handled by the well known exception handling concept which is part of the C++ language. In case of unexpected exceptional behaviour or errors during program execution MITK classes throw exceptions. MITK exceptions are always objects of the class mitk::exception or its subclasses. Exceptions should always be thrown by using the pre defined exception macros. If you want to throw a mitk::exception in your code, simply use the following macro. -TODO +\code +//This command will throw a mitk::exception and add the message. +//The macro will also add filename and line number to the exception +//object. +mitkThrow() << "Here comes your exception message"; +\endcode + +You can also stream more complex messages, e.g. adding integers or other variables to your exception messages, like shown in the following example. + +\code +mitkThrow() << "This time we show the values of some variables:" << m_MyObject->GetSize() << m_MyInteger; +\endcode + +In general exception emit no logging messages by default because they are intended to be catched by overlying classes. This classes should then decide what to do, e.g. to log an error message or handle the exception in another way. See \li LoggingPage for more details on error logging. + +\ref SpecializedExceptionHandling Defining and Using more Specialized Exceptions + +The basic MITK exception concept was kept very simple and should suffice in many cases. But if you need more specialized exceptions, this is also possible. Nevertheless all MITK exceptions should be subclasses of mitk::exception. You can define your own exception classes by simply implementing new classes which derive from mitk::exception. Thus, you can catch your exception seperately when needed. By using the mitkExceptionClassMacro implementing new exception classes is simple, like shown in the following code example. + +\code +#include +#include -\section Sec2 Section 2 +class mitk::MySpecializedException : public mitk::Exception + { + public: + mitkExceptionClassMacro(mitk::MySpecializedException,mitk::Exception); + }; +\endcode -TODO +To throw your specialized exception you should use the corresponing macro, which is shown in the next code snippet. \code -set(MODULE_CUSTOM_TESTS - ... - mitkImageVtkMapper2D.cpp -) +mitkThrowException(mitk::MySpecializedException) << "this is error info"; \endcode \ No newline at end of file