PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
New WINDEV 28 feature!
  • In this lesson you will learn the following concepts
  • Overview
  • Operating mode
  • Implementation
  • Types of errors
  • Automatic error handling: a training example
Lesson 7.2. Automatic error handling
In this lesson you will learn the following concepts
  • What is automatic error handling?
  • Configuring the automatic error handling.
Lesson duration

Estimated time: 10 mn
Previous LessonTable of contentsNext Lesson
Overview
WINDEV handles the 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 an error is detected by a WLanguage function:
  • 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 its details can be retrieved using ErrorInfo.
This second operation can be automatically managed by the WINDEV error handling system.

Implementation

The automatic error handling can be configured:
  • in the code editor: click the link "If error: By program" in the code editor:
    Configuring the automatic error handling
  • 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, we will use a training example provided with WINDEV.
    1. Go to the WINDEV home page (Ctrl + <).
    2. On the home page, click "Open an example". The list of complete, training and unit examples provided with WINDEV is displayed.
    3. Type "Error" in the search area. Only the examples containing this word are listed.
      Examples from the home page
    4. Double-click "WD Auto Error Management". The project is loaded.
  • This project shows how to handle:
    • 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.
  • Test the project (click Test project in the quick access buttons).
    1. Click "Handle non-fatal errors".
    2. The following window appears.
      Non-fatal error handling
    3. Click "Test error handling".
    4. When running the line of code 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 operation" and close the window.
  • Click "Handle fatal errors".
    1. The following window appears. This window is used to check the error when an integer is divided by 0.
      Fatal error handling
    2. Click "Test error handling".
    3. 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.
    4. Click "OK" and close the window.
  • Click "Handle errors on several levels".
    1. The following window appears. This window checks an error on multiple levels (e.g., process calling a procedure that opens an archive that does not exist).
      Error handling on multiple levels
    2. Click "Test error handling".
    3. 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.
    4. Click "Cancel operation".
  • Stop the application test.

Example

WINDEV also offers an automatic handling system of HFSQL errors. For more details, see the "WD Detecting HFSQL Errors" training example (provided with WINDEV). This example is accessible from the WINDEV home page.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 28
Comments
Click [Add] to post a comment