Error Handling in Qlikview
Error Handling in Qlikview
There are four special variables which can be used for error handling in the script:
ErrorMode
Determines the action to be taken by QlikView when an error is encountered during script execution. By
default (ErrorMode=1) the script execution will halt and the user will be prompted for action (non-batch
mode). By setting ErrorMode=0 QlikView will simply ignore the failure and continue script execution at the
next script statement. By setting ErrorMode=2 QlikView will trigger a "Execution of script failed" error
message immediately on failure, without prompting the user for action beforehand.
Example:
set ErrorMode=0;
ScriptError
The error code of the last executed script statement. This variable will be reset to 0 after each successfully
executed script statement. If an error occurs it will be set to an internal QlikView error code. The error code
is a dual value with a numeric and a text value. Error codes are as follows:V
1 No Error
2 General Error
3 Syntax Error
4 General ODBC Error
5 General OLEDB Error
6 General XML Error
7 General HTML Error
8 File Not Found
9 Database Not Found
10 Table Not Found
11 Field Not Found
12 File Has Wrong Format
Examples:
set ErrorMode=0;
load * from abc.csv;
if ScriptError=8 then
exit script;
//no file;
end if
Another Way we can use :
set ErrorMode=0;
load * from abc.csv;
if $(ScriptError)=File Not Found then
exit script;
end if
ScriptErrorDetails
Returns a more detailed error description for some of the error codes above. Most importantly this variable
will contain the error message returned by ODBC and OLEDB drivers for error codes 3 and 4.
ScriptErrorCount
Returns the total number of statements that have caused errors during the current script execution. This
variable is always reset to 0 at the start of script execution.
Example:
Set ErrorMode=0;
Load * from abc.csv;
if ScriptErrorCount >= 1 then
exit script;
end if
ScriptErrorList
This variable will contain a concatenated list of all script errors that have occurred during the last script
execution. Each error is separated by a line feed. The values of all variables above will remain after script
execution. The value of ScriptError, ScriptErrorDetailed, ScriptErrorCount and ScriptErrorList for
error handling inside the script is of course dependent on the use of ErrorMode=0.