If an unhandled error occurs in a script of any kind it will cause a Global Script named the Script Error Alert to be executed. Depending on where the error is coming from the ThisUnit, ThisScript or ThisInterface globals may also be set to indicate in what script or unit script or interface script the error occurred.
Inside the Script Error Alert you can use the Last Error, Last Error Message, and Last Error Date verbs to get the error message and exact time for logging or alerts as needed.
If a scripting error occurs in the Script Error Alert script that will not cause the script to be executed again to avoid an infinite recursion and eventual crash situation. Any error in the error handling script will be written to the log with as much information as possible but will not cause other actions to happen.