PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Declaring several processes of general exceptions
  • Declaring the processes of general exceptions in the same process
  • Declaring the exception processes in different processes
  • Nesting the exception processes in different processes: managing the exception via a higher level
  • Main remarks
  • An exception process can only be used once
  • Quality of WLanguage code for processing the exception
  • Quality of the code following an exception process
  • Special case
  • Exception process and component
  • Exception process and threads
  • Functions for managing the general exceptions
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Mechanism of general exceptions
Overview
A process of general exception is available for all the components of the object with which it is associated. This exception process can be used as long as the object is available.
A process of general exception can be declared in any process. After the execution of an exception process, the WLanguage code following the process is run.
Some examples:
  • If the exception process is declared in the initialization code of project, it is valid for any error that occurs in the project.
  • If the exception process is declared in the declaration code of the global variables of a window, page or report, it is valid for any error that occurs in the window, in the page, in a window control, in a page control or in a procedure local to the window or to the page. This exception process is not valid anymore when the window or the page is closed.
  • If the exception process is declared in any process, it is valid for any error that occurs in this process. This exception process will not be valid anymore once the process is completed. Therefore, an exception process declared in the click code of a button will only be valid in this process and in all the procedures called from this process.
AndroidAndroid Widget Java Caution: The mechanism of general exceptions is not available.. Only the specific exceptions (WHEN EXCEPTION IN) are available.
Declaring several processes of general exceptions

Declaring the processes of general exceptions in the same process

The second exception process will replace the first exception process from the declaration of second exception process.
Example: In the Example procedure, if an error occurs:
  • In <Code1>: no management of exceptions is enabled unless an exception procedure was defined in the calling code (in the current window or in the current page or in the project).
  • In <Code 2>: the active exception process is <Process of Exception 1>.
  • In <Code 3>: the active exception process is <Process of Exception 2>.
PROCEDURE Example()
<"Code 1">
WHEN EXCEPTION
<Process of Exception 1>
END
<"Code 2">
WHEN EXCEPTION
<Process of Exception 2>
END
<"Code 3">

Declaring the exception processes in different processes

If the exception processes are declared in embedded objects (project and window, project and page, window and control or page and control for example), the exception process of the smallest object hides the main exception process during the lifetime of this object.
Example: If the following two exception processes are declared:
  • exception process A declared in the initialization code of a project,
  • exception process B declared in the declaration code of global variables of a window or page.
For all the errors that occur in the window or in the page, the exception process B will be used and it will hide the exception process A.

Nesting the exception processes in different processes: managing the exception via a higher level

If the exception processes are declared in embedded objects (project and window, project and page, window and control or page and control for instance), the error can be managed in the exception process of higher level.
All you have to do is use the EXCEPTION keyword in the exception process.
Example:
// Initialization code of project
WHEN EXCEPTION
// Stop the application
EndProgram()
END
// Global procedure ControlValue
// Returns the value of the control or "" if the control does not exist
PROCÉDURE ControlValue(ControlName)
WHEN EXCEPTION
// For the UnknownControl error, "" is returned
IF ExceptionInfo(errCode) = UnknownControl THEN RESULT ""
// For another error, the error manager of the project is called
EXCEPTION
END
Main remarks

An exception process can only be used once

An exception process can only be used once. If a second exception occurs, the exception process will not be run. If an exception process of higher level exists, this exception process will be run.
To re-enable an exception process once it has been used, call ExceptionEnable. Caution: this function must be used with great care.
WINDEVWINDEV Mobile For example: A general exception process was declared at window level and at project level.
A first programming error occurs in the window. This error is processed by the exception process of the window.
A second error occurs in the window. This error is processed by the exception process of the project.
WEBDEV - Server code For example: A general exception process was declared at page level and at project level.
A first programming error occurs in the page. This error is processed by the exception process of the page.
A second error occurs in the page. This error is processed by the exception process of the project.

Quality of WLanguage code for processing the exception

An exception process cannot be used inside a WLanguage exception process. We recommend that you check the quality of the code in the exception processes because any error will trigger the display of the standard window/page of the security mechanism of WLanguage.

Quality of the code following an exception process

After the execution of an exception process, the WLanguage code following the process is run. We recommend that you pay attention to the quality of this code (to avoid displaying an error message).
Example: In the following code, {"Control1"}..Value = 5 triggers the exception process. At the end of the exception process, the same code line is re-run: the exception was already processed and the security mechanism of WLanguage is triggered.
// Exception process
WHEN EXCEPTION
// Process to perform if an exception occurs
Trace("Error")
END
// Programming error: the Control1 control does not exist
{"Control1"}..Value = 5
To avoid this problem, at the end of the exception process, we advise you to:
  • Make sure that the problem is corrected and that it will not happen again.
  • Use the RETURN and RESULT keywords to exit from the current process.
  • Use ReturnToCapture to give control back to the user.
    WEBDEV - Server code This feature is not available.
  • Use EndProgram to close the application.
Special case
A general exception process cannot be declared in the composite statements such as:
  • FOR
  • LOOP
  • WHILE
In this type of statement, use the specific exception process.

Exception process and component

If a general exception process is performed both in the initialization code of the component and in the initialization code of the project containing the component, the exception process of the project will be run when an error occurs in one of the component elements.

Exception process and threads

If a general exception process is set in the project initialization code, it will be triggered if an exception occurs:
  • in the main thread,
  • in a secondary thread started by ThreadExecute.
However, if the secondary thread triggers an exception, it will not be possible to find out its origin with ExceptionInfo in the project code. To find out the origin of an exception in a secondary thread, the exception process must be included in the secondary thread.
Functions for managing the general exceptions
Functions specific to the management of exceptions can be used with the general exception processes:
Versions 16 and later
ExceptionDisplay
New in version 16
ExceptionDisplay
ExceptionDisplay
Displays the standard window of exceptions with the content of the current exception
Versions 09 and later
ExceptionEnable
New in version 09
ExceptionEnable
ExceptionEnable
Re-enables the current exception process if the exception was corrected.
Versions 09 and later
ExceptionInfo
New in version 09
ExceptionInfo
ExceptionInfo
Retrieves information about the current exception.
Versions 10 and later
ExceptionPropagate
New in version 10
ExceptionPropagate
ExceptionPropagate
Propagates an exception.
Versions 10 and later
ExceptionRestoreParameter
New in version 10
ExceptionRestoreParameter
ExceptionRestoreParameter
Restores the exception process of a process.
Versions 09 and later
ExceptionThrow
New in version 09
ExceptionThrow
ExceptionThrow
Artificially triggers the security mechanism of WLanguage by throwing an exception.
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment