Exception Handling
The compiler is used to write your own exception programs for handling particular system events.
These are the exceptions:
- Division By Zero Exceptions.
- Shutdown Exceptions (after the last cycle).
- Startup Exceptions (before the first cycle).
-
-
Exception handling is supported for both Normal and Optimized PLC code generation.
- In the sub-program that handles the exception you can perform any safety or trace operation.
- Then, select between these possibilities:
- Return without any special call.
- In this case the standard handling is performed:
- A system error message is generated.
- The result of the division is replaced by a maximum value and the application continues.
- In this case the standard handling is performed:
- Call the FatalStop function.
- The runtime then stops immediately in Fatal Error mode.
- Call the CycleStop function.
- The runtime finishes the current program and then turns in "cycle setting" mode.
- Return without any special call.
Handlers can also be used in DEBUG mode for tracking the bad operation.
- Put a breakpoint in the handler.
- When stopped, the call stack shows the location of the division in the source code of the program.
Division By Zero Exceptions
You can write your own exception program for handling the Division by zero exception.
In this procedure, you must follow for setting an exception handler:
- Create a new sub-program without any parameter that will handle the exception.
- In the editor of global defines, insert this line:
#OnDivZero SubProgramName
Shutdown Exceptions
You can write your own exception program to be executed after the last application cycle when the runtime system is cleanly stopped.
- Create a new main program that handles the exception.
It cannot be an SFC program. - In the editor of global defines, insert this line:
#OnShutdown ProgramName
-
-
You cannot put breakpoints in the Shutdown program.
Startup Exceptions
You can write your own exception program to be executed before the first application cycle is executed.
- Create a new main program that will handle the exception.
It cannot be an SFC program. - In the editor of global defines, insert this line:
#OnStartup ProgramName
-
-
The program is executed before all other programs within the first cycle.
This implies that the cycle timing can be longer during the first cycle.
You cannot put breakpoints in the Startup program.