PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • This lesson will teach you the following concepts
  • Overview
  • Operating mode
  • Implementation
  • Types of affected errors
  • Automatic management of errors: a training example
Lesson 7.2. Automatic management of errors
This lesson will teach you the following concepts
  • What is the automatic management of errors?
  • Using the automatic management of errors.

Estimated time: 10 mn
Previous LessonTable of contentsNext Lesson
Overview
The errors can be automatically managed by WINDEV. This feature helps you reduce the number of code lines while centralizing the management of errors. The use of this feature also makes the code easier to read.

Operating mode

Two operations are performed when an error is detected by a WLanguage function:
  • an error value is returned by the function (for example, fOpen returns "-1" if the specified file was not opened).
  • the error is detected by WLanguage (the ErrorOccurred variable is set to True) and the error details are returned by ErrorInfo.
This second operation can be automatically managed by the error management of WINDEV.

Implementation

The automatic management of errors can be configured:
  • in the code editor: all you have to do is click the link "If error: By program" in the code editor:
  • by programming with ErrorChangeParameter.

Types of affected errors

Two types of errors can occur in WLanguage:
  • the "non-fatal" errors (also called runtime errors): in most cases, these errors are managed in the code and they do not stop the application. For example, opening a file that cannot be accessed or an archive that does not exist.
  • the "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 ...). 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 mechanism for managing errors is used to manage these two types of errors according to different methods in order to specify behaviors adapted to the errors that occur.
Automatic management of errors: a training example
  • To understand the different error cases, we will be using a training example supplied with WINDEV.
    1. Close the current project if necessary. The home window is displayed.
    2. In the home window, click "Open an example". The list of complete examples, training examples and unit examples supplied with WINDEV is displayed.
    3. Type "Error" in the search area. Only the examples containing this word are listed.
    4. Select the "WD Auto Error Management" project. The project is loaded.
  • This project presents the management:
    • of a non-fatal error (opening an archive that does not exist).
    • of a fatal error (division by 0).
    • of an error on several levels.
  • Run the project test by clicking (among the quick access buttons).
    1. Click "Managing a non-fatal error".
    2. The following window is displayed.
    3. Click the "Test this error management" button.
    4. When running the code line that triggers the error, an error message is displayed, allowing the user to retry the operation, cancel the operation or stop the application. The "Debug" option should be used:
      • in test mode, to directly debug the application.
      • in executable mode, to debug an executable directly from WINDEV.
    5. Click "Cancel the operation" and close the window.
  • Click "Managing a fatal error".
    1. The following window is displayed. This window is used to check the error when an integer is divided by 0.
    2. Click the "Test this error management" button.
    3. When running the code line that triggers the error, a procedure is automatically called. This procedure is used to display the error message and to stop the current process.
    4. Click "OK" and close the window.
  • Click "Managing an error on several levels".
    1. The following window is displayed. This window is used to test an error on several levels (process calling a procedure that opens an archive that does not exist).
    2. Click the "Test this error management" button.
    3. When running the code line that triggers the error:
      • the procedure returns "False" to the calling process.
      • the calling process displays an error message and stops the process.
    4. Click the "Cancel the operation" button.
  • Stop the application test.

Example

WINDEV also proposes an automatic management of HFSQL errors. See the "Detecting HFSQL errors" training example (supplied with WINDEV) for more details. This example can be accessed from the home window of WINDEV.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 23
Comments
Click [Add] to post a comment