You want to use a try except block. The try defines code that is expected (allowed) to raise errors, and the except is run when the error occurs. You can define the types of error that are allowed to happen. Make sure that you need to catch the error though - errors (exceptions) are supposed to be infrequent else you have a design flaw
this is what i actually do ,but it is andly only in some cases
what i mean is another thing , that should “cover” all module (or i guess) or i’m wrong?
i see in some script something as :
class Exception(Exception):
# other code that not recall
You seem to be on the right track. I usually use something like this to stop the game immediately when an unexpected error occurs.
try:
# call your code here
myClass.main()
except: # catch all exceptions
# end the game and re-raise the exception
bge.logic.endGame()
raise
If you have separate modules, you’ll have to either do something like this in each of them or just have it once in a central script that calls each module.
I think the whole purpose of doing this is to make it easier to find and rectify such errors. Otherwise an error may happen on only one frame and you may not notice it, or the error that occurred may trigger other errors to occur every frame, making it difficult to identify the original error as it may be pushed out of the console buffer before you end the game.
Check out “sys.execpthook” this is the exception handler that process all uncaught exceptions. I understand your pain with the “exception throwup” that often buries the real cause.
I’ve considered creating a handler that that would attempt to suppress repeated exceptions so I could see a list of the unique exceptions that happened during the run.