Additional Keywords

Else Clause

You can use the else keyword to define a block of code to be executed if no errors were raised:

try:  
  print("Hello")  
except:  
  print("Something went wrong")  
else:  
  print("Nothing went wrong")

In this example, the try block does not generate any error:

Output:
Hello
Nothing went wrong

Finally

The finally block, if specified, will be executed regardless if the try block raises an error or not.

try:  
	<statement>
	...
except:  
	<statement which is excecuted if exception occurs>
	...
finally:  
	<statement which is always exceuted>
	...
Powered by Forestry.md