Most JS API functions and Javascript operations will "thow" an error if you use them incorrectly... |
In Javascript, the Error object (or derivative) is used to provide details of an error. All error objects have two properties in common:
You can throw errors in your own code as follows:
throw new Error("your message"); |
If the error is not caught by the calling code it will ripple up to the Javascript engine running your script. When this happens a warning message will be shown in the console for the player under which the script is running (so the end-user might not see it unless they are in debug mode and have switched to the player associated with the script). In addition, errors are usually written to log files or the terminal.
Catch errors as follows:
try { // do something } catch(e) { // this code will run if an error is thrown by something console.log(e.message); } finally { // this block is optional // it will always be run regardless of whether an error is thrown or not // which seems pointless, as surely... } // ... you'd just run that code here instead?! |
The JS API documentation indicates the likelihood of an error being thrown by a function by showing a possible return value of |
AvailabilityRequires:
|
ContentsJump to: |
See alsoRelated articles:
|