|
|
|
|
- In this lesson you will learn the following concepts
- Overview
- Operating mode
- Implementation
- Types of errors
- Automatic error handling: a training example
Lesson 9.2. Automatic error handling In this lesson you will learn the following concepts - What is automatic error handling?
- Configuring the automatic error handling.
WEBDEV can handle errors automatically. This feature helps you reduce the number of lines of code while centralizing error handling.
The use of this feature also makes the code easier to read. Operating mode Two operations are performed when a WLanguage function detects an error: - the function returns an error value (e.g., fOpen returns "-1" if the specified file could not be opened).
- WLanguage detects the error (the ErrorOccurred variable is set to True) and the details of the error can be retrieved with ErrorInfo.
The second operation can be done automatically by the WEBDEV error management assistant. Implementation The automatic error handling can be configured: - in the code editor: click the link "If error: By program" in the code editor:
- programmatically with the ErrorChangeParameter function.
Types of errors Two types of errors can occur in WLanguage: - "non-fatal" errors (also called runtime errors): in most cases, these errors are handled in the code and do not stop the application. For example, opening a file that cannot be accessed or an archive that does not exist.
- "fatal" errors (also called programming errors): in most cases, these errors are linked to a development problem (access to a non-declared file, use of non-existing controls, etc.). A "fatal" error can also occur after a "non-fatal" error that was not processed properly. In this case, the application will be stopped.
The error handling mechanism handles these two types of errors using different methods to set behaviors adapted to the errors encountered. Automatic error handling: a training example - To understand the different error cases and how they are managed, we will use an example provided with WEBDEV.
- Go to the WEBDEV home page (Ctrl + <).
- On the home page, click "Open an example". The list of complete examples and training examples provided with WEBDEV is displayed.
- Type "Error" in the search area. Only the examples containing this word are listed.
- Select the "WW_Auto_Error_Management" project. The project is loaded.
- This project presents:
- how to handle a non-fatal error (opening a non-existent archive).
- how to handle a fatal error (dividing an integer by 0).
- how to handle an error on multiple levels.
- Test the project (click
in the quick access buttons).- Click "Fatal error".
- The following page is displayed. This page is used the test the error when an integer is divided by 0.
- Click "Test error handling".
- When running the line of code that triggers the error, a procedure is automatically called. This procedure displays the error message and stops the current process.
- Click "OK".
- Click "Non-fatal error".
- The following page is displayed.
- Click "Test error handling".
- When running the line of code that triggers the error, an error message is displayed.
- Validate the error message.
- Click "Error on multiple levels".
- The following page is displayed. This page is used to test an error on multiple levels (process calling a procedure that opens an archive that does not exist).
- Click "Test error handling".
- When running the line of code that triggers the error:
- the procedure returns "False" to the calling process.
- the calling process displays an error message and stops the process.
- Validate the error message.
- Close the browser to end the test.
| | |  | Example | WEBDEV also handles HFSQL errors automatically. For more details, see Assisted HFSQL error handling. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|