Python - Undo script if script fails Sometime when writing a python script I will run into an error such as syntax or some Exceptions. The script will partially execute, but not everything. This is frustrating because I have to manually undo what the script executed before I can run the script again. Is there a way that I can have the script undo what it has done if it fails. I want the script to only make permanent changes if it ran without error.
You could enable Undo support for your operator. Below

bl_label = "Simple Object Operator"


add

bl_options = {'REGISTER', 'UNDO'}


But I wouldn't make the operator undo itself on errors, rather let the user do it if necessarily. However, your script shouldn't raise exceptions in the first place, but check in the operator's poll() classmethod, if all pre-conditions are met. Or let it return {'CANCELLED'} inside the execute() body before something is damaged.