This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20 R7
throw
|
throw ( errorCode {; description} ) | ||||||||
Parameter | Type | Description | ||||||
errorCode | Longint |
![]() |
A long integer representing the error code. | |||||
description | Text |
![]() |
A text providing a description of the error. | |||||
throw {( errorObj )} | ||||||||
Parameter | Type | Description | ||||||
errorObj | Object |
![]() |
An object containing properties to build the error | |||||
The throw command creates an error that will be thrown either immediately or when the calling method returns to its caller (deferred mode).
When you encounter a situation in your 4D code where an error condition arises, you can use the throw command to explicitly throw an error and provide a specific error message or error number. This can be useful for signaling exceptional conditions or invalid inputs.
Errors thrown using the throw command are managed by the 4D runtime as any normal error: the standard error dialog is displayed unless an interception method has been installed using the ON ERR CALL command.
The command supports three syntaxes:
It specifies the error code and an optional description text, the error is thrown immediately.
If no description is provided, it is filled with:
errorObj object allows for more detailed error information and control over error handling. It can contain the following properties, as well as any custom property that you can refer to using placeholders within the message property.
property | type | description |
componentSignature | text | Four latin letters signature to uniquely identify the source of the error.
|
errCode | number | Error code.
|
message | text | Description of the error.
|
deferred | boolean | True if the error should be deferred when the current method returns or at the end of the Try block. Default value is false. |
When you use this syntax, the errorObj object is returned in Last errors.
Note: It is possible to call the command several times in the same project method to generate several errors. You can use the deferred option to send all errors at once.
It throws all current errors in deferred mode, meaning they will be added to a stack and handled when the calling method returns. This is typically done from within an ON ERR CALL callback.
var $code : Integer
var $description : text
$code:=50042 //Custom code
$description:=“This is a custom error”
throw($code ;$description) // Throws an error with message "This is a custom error" and errCode = 50042
throw({errCode: 1; message: "This an error"}) // Throws an error with errCode = 1 and message "This an error"
throw({errCode: 1}) // Throws an error with errCode = 1 and message "Error code: 1 (host)"
throw({message: "This an error"}) // Throws an error with errCode = -1 and message "This is my error"
throw({message: "This is my error"; deferred: True}) // Throw an error with message "This is my error" and errCode = -1 in deferred mode
throw({componentSignature: "xbox"; errCode: 600; name: "myFileName"; path: "myFilePath"; deferred: True})
// Throws an error with message "File myFileName not found (myFilePath)" in deferred mode
Product: 4D
Theme: Interruptions
Number:
1805
Created: 4D v20 R2
Modified: 4D v20 R5
4D Language Reference ( 4D v20 R7)