ErrorLib 1.0.8-master SHA: 810228da25
Definition and raise of errors in source code

Direct call of error

An error can be set everywhere in the code. This error with the error-text and additional metadata can be defined directly in the function which sets the error, or it can be defined elswhere before as globar error. If the error should not be define before the SetError function is used to raise the error.

Here an Example of a simple SetError call is shown:

TestErrorReaction, // Function to be called on first time setting the error
NoOnErrorResetReaction, // Function to be called on resetting the error
"Test Error 1", // Short Description
"DOC_D Ein Fehler am digitalen Ausgang wurde detektiert. Mögliche Ursachen:<br>-Überlast<br>-Kursschluss zur Masse<br>-Kursschluss zur 24V Versorgung<br>-Übertemperatur"\
"DOC_E A Fault at the digital Output was detected. Possible reasons:<br>-Overload<br>-Short to ground<br>-Short positive supply<br>-Thermal overload");
bool NoOnErrorResetReaction(void)
This function is called if no Reaction is required after an error reset.
Definition: Error.c:341
#define SetError(ID, PERMISSION, ON_ERROR, ON_ERROR_RESET, DESCRIPTION, HELP)
Set an error without data.
Definition: Error.h:225
@ DEVELOPER_RESET
Can be reset by user with Developer access level.
Definition: Error.h:57
@ PROFESSIONAL_RESET
Can be reset by user with Professional access level.
Definition: Error.h:56
@ USER_RESET
Can be reset by user with User access level.
Definition: Error.h:55
#define SampleErrorID_1
Definition: Sample_Errors.h:16

In this example the error with the predefined identifier SampleErrorID_1 is raised. The identifier should be unique in project, but it is not neccessary for the error-system to work. Due to this the uniqueness is not checked anywhere. It is a good practice to define all error-identifier in a central file Error_ID_Device.h.

This error is resettable from users of the group user, professional and developer. This field is an or-concatenated list of the flags defined in the enum ERROR_FLAGS.

The error reaction which is called after raising this error is TestErrorReaction, which must be defined elswhere (see Page Actions on Error set and reset for details). On error reset no action is performed.

Text and description are displayed in the error-log. The helptext is shown on pc after pressing F1. It can contain several lines in german and english. See page Help-texts in Errors for details.

The german helpwindow:

English version:

In this example the headerfile must be included and the identifier defined (normally done in Error_ID_Device.h):

#include "lib/Error/Error.h"
#define SampleErrorID_1 50001

Call of a predefined error

If the error is raised from several codelines, the error can be defined on a central place in code. The definition is shown in the following example:

NoOnErrorReaction, // Function to be called on first time setting the error
NoOnErrorResetReaction, // Function to be called on resetting the error
"Test Error 2", // Short Description
"DOC_D Testfehler 2"\
"DOC_E Test Error 2");
void NoOnErrorReaction(void)
This function is called if no Reaction is required after an error.
Definition: Error.c:332
@ PLC_RESET
Can be reset by the PLC.
Definition: Error.h:58
DefineError(50002, DEVELOPER_RESET|PROFESSIONAL_RESET|USER_RESET|PLC_RESET, NoOnErrorReaction, NoOnErrorResetReaction, "Test Error 2", "DOC_D Testfehler 2" "DOC_E Test Error 2")
Definition of an error. Can be used if Error is set from more than one codeline.
#define SampleErrorID_2
Definition: Sample_Errors.h:17

The fileds of the definition are the same than the direct call.

This error can be raised by this simple line:

#define SetErrorId(ID)
Set an error which is previously defined by "DefineError".
Definition: Error.h:672

If the call should be done in a different file than the declaration, it must be visible in the calling file. This can be done with a declaration in the header file:

DeclareError(50002)