Error Handling
We handle errors (and warnings) as values, not as exceptions. Our library
should not throw any exceptions, instead functions which can fail should return a
Status
or a
Result
if they return a value. This allows us to provide detailed reports about what happened during the
execution of a function, including warnings and custom success messages holding additional
information, like the exact source of the message. Furthermore, this approach enforces explicit
error handling, even if the dev decides to ignore the error, before accessing the return value of a
function (because the type is different). To see an example how you can handle such return values
see the
CLI tool.
For more advanced usages see
InnamarkTag.
Status
A
Status
represents the outcome of a function, without a return value, that is not guaranteed to
succeed. To be able to report any issues (or just additional information) that occurred during the
execution of a function, the class
Status
contains a list of Events that occurred during the execution. A
Status
that represents a success might not contain an
Event.
Multiple Status objects can be combined using
appendStatus and
prependStatus to propagate the reports.
Event
An
Event
represents different kinds of events that can occur during the execution of a function. There are 3
base variants:
The variants
Warning
and
Error
are abstract: For each event that can occur, a unique class must be created that overrides the
function getMessage(): String to explain the event. If a success message with additional
information is required, a new class inheriting from
Success
can be created. All variants, but the default
Success
variant, require a source string which should explain the origin of the event (e.g.,
className.functionName).
Result
A
Result
represents the outcome of a function, with a return value, that is not guaranteed to
succeed. It functions like a
Status
(it uses a
Status
internally) but also has a generic member value that can contain the return value. When the
Status
is in success or warning state it must contain a value, otherwise it should not
contain a value.