- The assertions
- Customizing the window of assertions
WINDEV, WEBDEV and WINDEV Mobile include several tools and features used to optimize the applications and the sites.
The main available features are as follows:
An assertion is used to check a condition when running the application.
If the condition fails, a dialog box containing the check details is displayed.
The developer can access the runtime stack, which means all calls that resulted in this result.
To define an assertion, simply use dbgAssert
with the following parameters:
- the condition to check,
- the message to display if the condition is not checked.
// CClient variable
clClient is CClient
// Create the client
// The clClient object must have been instantiated
dbgAssert(clClient<>Null, "The object was not instantiated")
By default, the assertions are enabled in test mode only.
The assertions can be enabled in deployment: simply use dbgEnableAssert
: The condition used in the assertion is run by WLanguage only
when the assertions are enabled. Therefore, the operating mode may differ in test mode and in executable mode.
You must be very careful when using functions in the condition given to dbgAssert
. Indeed, if the function used performs an initialization or a connection, this operation will not be performed in the application used in "executable" mode.
On the other hand, this operating mode allows you to run "more tests" without slowing down the deployed application. This gives you the ability to easily enhance the applications.
Assertions can be used to run "specific" cases or to check the "prerequisites" of a function. This allows you to check the case that should never happen:
- using an empty string while a logical name is expected,
- entering a path to a file that does not exist, ...
The assertions cannot replace the standard management of errors
. But implementing an assertion allows you to be informed and to find out whether a problem occurred via the execution stack.
The assertions are also used to guide you when the development is performed by several developers: the "calling" code must provoke no assertion in the code that is "called".
Customizing the window of assertions
By default, the windows for managing the errors, the exceptions and the assertions are included in the application. These windows are available in English and in French.
To customize these windows (or to translate them), all you have to do is import the corresponding windows into your project.
- In the ribbon:
- On the "Project" pane, in the "Project" group, expand "Import" and select "WINDEV elements and their dependencies".
- On the "Project" tab, in the "Project" group, expand "Import" and select "WINDEV Mobile elements and their dependencies".
- Select the directory of the elements to import: "Programs\Data\Preset windows\Assertion - Error - Exception".
- Select the windows to import:
|WINDEV||WINDEV Mobile||Type of window|
|WD_DisplayAssert.wdw||WM_DisplayAssert.WPW||Window for managing the assertions|
|WD_DisplayError.wdw||WM_DisplayError.WPW||Window for managing the errors|
|WD_DisplayException.wdw||WM_DisplayException.WPW||Windows for managing the exceptions|
|WD_ErrorTemplate.wdt||Template used by the WINDEV windows.|
- Validate. The windows are included in your project. These windows will be automatically used and they will replace the default windows.
Remark: To use the default windows, all you have to do is delete the imported windows from your project.
This page is also available for…