> For the complete documentation index, see [llms.txt](https://support.powerio.com/hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.powerio.com/hub/faq/faq-en/hvac-codesys-faq/automatischer-neustart-im-fehlerfall.md).

# Automatic restart in the event of an error

{% hint style="warning" %}
Please note that for the full functionality of the function *OnException* **at least firmware version 3.2** is required.

The function *OnException* is preconfigured for powerIO devices and is only recommended for powerIO devices.
{% endhint %}

## How can the control be automatically restarted in the event of an error?

The following article describes the function of how an exception during runtime can be logged and, in the exception state, the runtime or the device can be restarted.

## Description

* That the control in the event of an exception **without** **emergency stop** (no kernel panic) of the system, the message is logged and a restart of the CODESYS Runtime is performed. This is the “automatic soft reset in the event of an error”.
* That the control in the event of an exception **with “emergency stop”** (kernel panic) of the system, the message *tries* to log and a restart of the system takes place.

  This is the “automatic hard reset in the event of an error”

## Function description *OnExceptionWrapper*

In [Start project "Empty" ](/hub/downloads/en/codesys-hvac-templates/template-start.md)under the view *POU* the two functions

* *OnException* and
* *OnExceptionWrapper*

The function *OnExceptionWrapper*, calls the *OnException* function with the specified settings.

```iecst
OnException( 
	EventPrm:=EventPrm,
	xDebug := FALSE,
	xLogExceptionToFile:=TRUE,
	xRestartRuntimeOnException := TRUE,
	tExceptionFunctionTimeout := TIME#45S0MS
	);
```

## Enabling/disabling the exception handling function

1\. Click on "Task configuration "

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/a17783ad-3118-4508-870f-28e2ff3d4f84/user_cropped_screenshot.jpeg?tl_px=0,231\&br_px=859,712\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=122,212)

2\. Click on "System events"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/17d6f9e5-ba67-49c0-a42f-e26e029ddea3/user_cropped_screenshot.jpeg?tl_px=274,0\&br_px=1134,480\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,107)

3\. Check whether the "Exception" function already exists.

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/959b345f-8448-402d-9740-889e366bafed/user_cropped_screenshot.jpeg?tl_px=195,0\&br_px=1055,480\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,173)

4\. If present, check whether it is "Active"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/97f6a3fb-6992-46d4-b3f4-0048d7d99f92/screenshot.jpeg?tl_px=1905,0\&br_px=2765,480\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,177)

5\. If not active, then activate it

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/6ed9e473-a7e9-40ab-a11b-3d5a7fb4ad65/screenshot.jpeg?tl_px=1905,0\&br_px=2765,480\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,177)

## Adding the exception handling function

If you want to add exception handling for an existing project, you can copy the two functions from the [Start project "Empty" ](/hub/downloads/en/codesys-hvac-templates/template-start.md)and manually add the Event Task.

Proceed as described below:

1\. Navigate to "Task configuration "

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/b299d8ef-01ff-4bdf-a9e5-60610b76ab6e/user_cropped_screenshot.jpeg?tl_px=0,237\&br_px=859,718\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=166,212)

2\. Open the "System events" tab

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/fabaa8e3-458d-4506-be77-36339e0ddeec/user_cropped_screenshot.jpeg?tl_px=285,0\&br_px=1145,480\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,105)

3\. Click "Add event handler"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/b8682791-790f-4cad-b089-b1c1d0b2499a/user_cropped_screenshot.jpeg?tl_px=46,0\&br_px=905,480\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,131)

4\. Select event type "Exception"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/430c91c1-d6d7-4602-83a4-690c952034cb/user_cropped_screenshot.jpeg?tl_px=693,315\&br_px=1553,796\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,212)

5\. Enter exception name "OnExceptionWrapper"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/d08770c6-8fe3-4339-88e2-ded86e4caad0/user_cropped_screenshot.jpeg?tl_px=494,279\&br_px=1258,706\&force_format=png\&width=764)

6\. Click "POUs"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/586e7dc6-2d8e-4b1d-8352-cbb134b6478f/user_cropped_screenshot.jpeg?tl_px=803,293\&br_px=1568,720\&force_format=png\&width=764\&wat_scale=68\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=357,188)

7\. Click "OK"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/b407b030-9d13-48a1-9c06-bf8ba6c15cb6/user_cropped_screenshot.jpeg?tl_px=542,395\&br_px=1402,876\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,212)

8\. Switch the view to "POUs"

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/a0288e24-8490-45c5-a66b-b3926deb77a8/user_cropped_screenshot.jpeg?tl_px=0,1211\&br_px=859,1692\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=73,377)

9\. Open function "OnExceptionWrapper (FUN) "

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/90abd384-bc64-430d-8ada-452f8c7e72d6/user_cropped_screenshot.jpeg?tl_px=0,20\&br_px=859,501\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=143,212)

10\. Configure the "OnException" function

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2023-11-21/a1ce65ed-e2d1-42b2-8a01-601add236224/user_cropped_screenshot.jpeg?tl_px=325,427\&br_px=1185,908\&force_format=png\&width=860\&wat_scale=76\&wat=1\&wat_opacity=1\&wat_gravity=northwest\&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/77328A_standard.png\&wat_pad=402,212)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://support.powerio.com/hub/faq/faq-en/hvac-codesys-faq/automatischer-neustart-im-fehlerfall.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
