Home > front end >  Is a try except statement equivalent to execute or execute other?
Is a try except statement equivalent to execute or execute other?

Time:09-26

Try statements are new to me, so is a try except statement equivalent to execute or execute fail code?

This is how I see it in bash:

cmd || otherCmd

CodePudding user response:

try-except statement is a code block that allows your program to take alternative actions in case an error occurs. Python will first attempt to execute the code in the try statement. If no exception occurs, the except statement is skipped and the execution of the try statement is finished. If any exception occurs, the except statement will trigger. This way your program handle exceptions instead stopping.

  • Related