Page MenuHomePhabricator

Exception handling for MITK: exception base classes and documentation how to use them
Closed, ResolvedPublic

Description

Implement exception handling for MITK. The exception concept was already discussed in an internal MITK meeting. It will base on the ITK exception concept. There will be a central MITK exception class and also a MITK exception macro. The detailed concept will be documented in a wiki page as well as in a presentation.

Some standard guidelines will also be provided to unify exception handling in MITK.

Event Timeline

Alfred, would you please write some wiki document about your ideas? If there are meeting minutes, you could link them or copy the relevant parts. This sounds like a large project, which should be documented before starting implementation.

Here is a short overview about the idea of the exception handling for MITK:

The exception handling of MITK will be based on the exception handling of ITK since most parts of MITK "derive" from ITK. The idea of the ITK exception handling is very simple, there is one exception class and an exception macro to throw exceptions. Similary there will be a MITK exception and a MITK exception macro. This will enable users of the MITK library to indentify exceptions thrown in MITK and handle them in a proper way. The basic concept will be that simple to (hopefully) achieve that exceptions will be widely and consistently used by every MITK programmer.

Additionaly there will be the possibility to define exceptions inside MITK more specific if needed. To do so one can create a class which derives from MITK exception to model a more specific exception (e.g. IGTHardwareExperion for exceptions of IGT hardware like communication problems, etc.). There will we be a second macro which allows to throw such exceptions, simply by adding another parameter to the second macro which defines the type of the exception. This part of the concept should only be used if more specification of exceptions is needed, e.g. if an overlying class should only catch hardware exceptions because these exceptions can be handled in a proper way by this class.

The decision to not have a complex exception tree (like in java for example or in the std library) was reached conscientiously. Like told before the idea was to keep the concept as simple as possible.

So the scope of this bug it to provide a macro and tests for that macro but not to change exception handling in core?
(I really don't find that in your text and from the broad title of this bug, it could develop into a long-running project without defined end. Please add a short description of the scope here. I have set the flag to + regardless of that, I'm glad that somebody is working on this topic)

Hi, the scope of this bug is to provide (1) a environment for exceptions in MITK and (2) documentation including guidelines how to use exceptions in MITK.

The environment, as described in my comment above, consists of a MITK exception class and one or more exception macros.

Once the concept is implemented and the guidelines are finished we can start to adapt the exception handling all over MITK (including the core). This of course will be a big project and should be splitted into different bugs. Perhaps a meta bug like "adapting MITK to unified exception handling" will be a good idea for the second part.

A main idea of this project is to provide an unified exception environment and documentation as soon as possible. So at least new implementations can use the exception concept and we don't have to adapt them later. We can then start to adapt MITK step by step. Code parts which are prone to exceptions (e.g. readers/writers) should be adapted first, this may help to make MITK more stable.

I will change the title of this bug to avoid misunderstandings about the scope.

An important question concerning the implementation is where to add the new classes / macros.

In ITK, exceptions objects can be found in the folder code/common of the source tree. In MITK there is no "general" folder (e.g. core/code/common). Also, the exception classes does not fit into one of the current folders very well (the current folders are Algorithms, Controllers, CppMicroServices, DataManagement, Interactions, Interfaces, IO, Rendering and Testing).

I've figured out three alternatives:
(1) We add a new exception-specific folder (e.g. "Exceptions" or "ErrorManagement", etc.)
(2) We add a new general folder for classes which doesn't fit into other folders (e.g. "common" as in ITK)
(3) We use one of the current folders for exceptions, please make proposals.

So which alternative should we use?

Because of a new folder we decided for alternative 2. This was because there is also a "common" folder in itk and vtk. Additionally the new T11728 added to discuss the folder structure of MITK core.

[436bd0]: Merge branch 'bug-11354-ExceptionHandlingForMITK'

Merged commits:

2012-05-10 20:52:22 Alfred Franz [21e1d6]
removed old exception macros / added documentation


2012-05-10 20:13:59 Alfred Franz [c096c7]
added tests for the new macros and the streaming operators


2012-05-10 20:13:31 Alfred Franz [3caef7]
added streaming operators to the MITK exceptions which allow for the use of mitkThrow() << "My Message";


2012-05-10 20:12:38 Alfred Franz [853013]
added new exception macros in the style mitkThrow()


2012-05-09 19:10:09 Alfred Franz [37cc4f]
added test for mitkThrow() with parameter


2012-05-09 13:55:38 Alfred Franz [2babd1]
improved test of exception macro


2012-05-09 13:44:33 Alfred Franz [080554]
added new macro and help class for support of syntax "mitkThrow()<<"Messagetext""


2012-04-19 18:05:32 Alfred Franz [7f22c2]
added mitkExceptionClassMacro and adapted exception classes


2012-04-19 16:07:11 Alfred Franz [902f8e]
adapted IGT exceptions to new exception macros

you can throw them with the specialized exception macro now.


2012-04-19 15:52:28 Alfred Franz [694640]
added documentation to exception macros and simplified code

also fixed line endings


2012-04-19 15:14:18 Alfred Franz [1380a0]
added test cases for new macro


2012-04-19 15:13:48 Alfred Franz [b9edcf]
added exception macro for specialized exceptions


2012-04-19 11:05:00 Alfred Franz [7abcce]
first version of exception with macro is running now


2012-04-18 14:37:00 Alfred Franz [6fddce]
first implementation of MITK exceptions, with tests. Not working yet.


2012-03-27 17:15:28 Alfred Franz [fcef5b]
Merge branch 'bug-1770-ExceptionHandlingIGT' into bug-11354-ExceptionHandlingForMITK


2012-02-02 17:25:55 Alfred Franz [73c7ae]
added exception classes IGTException and IGTHardwareException

[5307ec]: Merge branch 'bug-11354-ExceptionHandlingForMITK'

Merged commits:

2012-05-11 09:26:30 Alfred Franz [d3c69c]
COMP: converted itk deriving test class to smart pointer

[8c0a9c]: Merge branch 'bug-11354-ExceptionHandlingDocumentation'

Merged commits:

2012-05-25 09:43:54 Alfred Franz [cdd56d]
DOC: some corrections of the documentation pages for Exceptions and Logging


2012-05-24 17:22:13 Alfred Franz [537540]
DOC: Added documentation for logging concepts.


2012-05-24 15:34:33 Alfred Franz [9e5c0d]
used veratim tag instead of code tag to make doxygen comments visible


2012-05-22 15:32:52 Alfred Franz [baba35]
DOC: further writing of exception handling documentation


2012-05-21 16:57:16 Alfred Franz [265693]
wrote documentation page for MITK exceptions


2012-05-21 14:41:14 Alfred Franz [5d03b1]
DOC: added concept page for exceptions and logging