OnException
From the Scripting Manual
procedure OnException(ErrorMessage: string); Parameter Info: ErrorMessage (String): A String containing the error that has occured. Description: This procedure will ONLY be called when the server crashes due to an unhandled exception.
Examples
begin
WriteFile('ErrorLog.txt',ErrorMessage);
// Dump the error to text file.
end;