AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de excepciones
  • 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 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 general exceptions
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
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.
For example:
  • If the exception process is declared in the project initialization code, 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.
AndroidWidget Android Java Remark:
  • The mechanism of general exceptions is not available.. Only the specific exceptions (WHEN EXCEPTION IN) are available. For more details, see Management of specific exceptions.
  • You can also use ExceptionChangeParameter with the epExecuteProcedureOverall constant in the project "Initialization" event.
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 Procedure Example, if an error occurs:
  • In the <Code1> no exception handling is active unless an exception procedure has been defined in the calling code (in the current window, page or project).
  • In <Code 2>: the active exception process is <Exception Process 1>.
  • At <Code 3>: active exception handling is <Traitement 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 treatments 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 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 example), 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:
// Project initialization code
WHEN EXCEPTION
	// Stop the application
	EndProgram()
END
// Global procedure ControlValue
// Returns the value of the control or "" if the control does not exist
PROCEDURE ControlValue(ControlName)
WHEN EXCEPTION
	// For the UnknownControl error, "" is returned
	IF ExceptionInfo(errCode) = UnknownControl THEN RETURN ""
	// 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 handled with care.
WINDEVWINDEV Mobile For example A general exception has been declared at both window and 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 - Código Servidor For example A general exception has been declared at page and 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, the line {"Field1"}...Value = 5 triggers exception handling. At the end of exception handling, the same line of code is re-executed: the exception has already been handled and the WLanguage safety mechanism is triggered.
// Exception process
WHEN EXCEPTION
	// Process to perform if an exception occurs
	Trace("Error")
END
// Programming error: field Champ1 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 SetFocusAndReturnToUserInput to give control back to the user.
    WEBDEV - Código Servidor This feature is not available.
  • Use EndProgram to close the application.
Special case
A general exception process cannot be declared in compound 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 general exceptions
Functions specific to the management of exceptions can be used with the general exception processes:
ExceptionDisplayMuestra la ventana estándar de excepciones con el contenido de la excepción actual.
ExceptionEnableRe-enables the current exception process if the exception was corrected.
ExceptionInfoRetrieves information about the current exception.
ExceptionPropagatePropagates an exception.
ExceptionRestoreParameterRestores the exception process of a process.
ExceptionThrowArtificially triggers the security mechanism of WLanguage by throwing an exception.
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/03/2025

Señalar un error o enviar una sugerencia | Ayuda local