CodingGuidelines » History » Version 4

J. Wienke, 05/16/2011 01:13 PM

1 1 J. Wienke
h1. Coding Guidelines
2 1 J. Wienke
3 1 J. Wienke
h2. Error Handling / Exceptions
4 1 J. Wienke
5 1 J. Wienke
* Use a common rsb::Exception for all exceptions
6 4 J. Wienke
* Rationale: Provides in the client application a way to handle all error from the communication layer uniquely
7 1 J. Wienke
** In languages where multiple inheritance is a pain, this class inherits from a runtime-like error and a custom exception tree with e.g. InvalidArgument is created underneath this root exception type.
8 1 J. Wienke
** If multiple inheritance is feasible, use it to reuse the existing language exception types.
9 1 J. Wienke
* in C++, don't use exceptions in constructors if you have objects that need a manual deallocation (to be verified that the destructor is not called for half-constructed instances)
10 1 J. Wienke
11 1 J. Wienke
h3. Barricade Strategy
12 1 J. Wienke
13 1 J. Wienke
* Generally user-induced data should be validated on the client level.
14 1 J. Wienke
* Exception to this rule is the converter mechanism -> user data member of the event class
15 1 J. Wienke
** Generally performing a validation already in client-level code is too expensive
16 1 J. Wienke
** OutRoute:
17 1 J. Wienke
*** Always using exceptions in the sending stack is not possible for asynchronous sending strategies.
18 1 J. Wienke
*** An invalid combination of data and converter is a (user-induced) fatal error
19 1 J. Wienke
*** exit the program (using a macro/function that creates a segfault in any case to get a backtrace, assert could be switched off and the error would be unnoticed or untraceable)
20 2 J. Wienke
** InRoute:
21 2 J. Wienke
*** two cases:
22 2 J. Wienke
***# no converter available:
23 2 J. Wienke
***#* Could happen because the receiver is not the cause of the message
24 2 J. Wienke
***#* for Reader (pull-based model) an exception is possible without any problems
25 2 J. Wienke
***#* Asynchronous case requires user checking for exceptions:
26 2 J. Wienke
***#** Special event or tag in event for error condition
27 2 J. Wienke
***#** A method for the user to check whether the event is an error condition or not
28 3 J. Wienke
***# Error while converting