python try ~ except ~ else

code


def func(a, b):                                                                                   
    try:
        print(a / b)
    except ZeroDivisionError as e:
        print('Exception Error:', e)
    else:
        print('finish')

#normal
func(1, 2)

#Exception error because it does not break at 0
func(1, 0)

Execution result

0.5
finish
Exception Error: division by zero

Recommended Posts

python try ~ except ~ else
Python> try: / except:
Python try / except notes
Try python
2016-10-30 else for Python3> for:
Try scraping with Python.
Try Debian + Python 3.4 + django1.7 ...
Try gRPC in Python
Try 9 slices in Python
Try using Tweepy [Python2.7]
[Python] Try using Tkinter's canvas
Try to understand Python self
Try Python output with Haxe 3.2
Try using Kubernetes Client -Python-
Try LINE Notify in Python
Try running Python with Try Jupyter
Try implementing Yubaba in Python 3
Try face recognition with Python
Try scraping with Python + Beautiful Soup
Azure Functions: Try Durable Functions for Python
Try IAM Database Authentication from Python
Python
Try the Python LINE Pay SDK
Try to operate Facebook with Python
Try implementing extension method in python
Try singular value decomposition with Python
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Let's try Fizz Buzz in Python
Try to calculate Trace in Python
Try PLC register access in Python
Try converting cloudmonkey CLI to python3 -1
Try face recognition with python + OpenCV
Try using Python argparse's action API
Try using the Python Cmd module
Try frequency control simulation with Python
EP 13 Take Advantage of Each Block in try / except / else / finally
Try using Leap Motion in Python
Try using Amazon DynamoDB from Python
Try to reproduce color film with Python
Try logging in to qiita with Python
Try using the Wunderlist API in Python
Try mathematical formulas using Σ with python
Try using the Kraken API in Python
Try working with binary data in Python
Try sending a SYN packet in Python
Try drawing a simple animation in Python
Try using Dialogflow (formerly API.AI) Python SDK #dialogflow
Try using Python with Google Cloud Functions
Try using Junos On-box Python # 2 Commit Script
[Python] Try pydash of the Python version of lodash
Try to operate Excel using Python (Xlwings)
Quickly try Microsoft's Face API in Python
Python amateurs try to summarize the list ①
Try HTML scraping with a Python library
Try calling Python from Ruby with thrift
Try using Junos On-box Python # 1 Op Script
Try text mining your diary in Python
Try hitting the YouTube API in Python
Try a functional programming pipe in Python
Try drawing a map with python + cartopy 0.18.0