Is there a way to add a function to the begining of a script so if it is halted it will output the error and line to a text file?