Python, about exception handling

Note about exception handling

Exception handling is processing that prevents the program from being interrupted due to an error occurring in the middle. For example, try the following:

list = [1,2,3,4,'a',5,6]
for i in list:
   print(i/10)

Then

0.1
0.2
0.3
0.4
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-78c5fd70e082> in <module>
      2 
      3 for i in list:
----> 4     print(i/10)

TypeError: unsupported operand type(s) for /: 'str' and 'int'

An error occurs due to the "a" notation, and the program is interrupted. Therefore, an error is displayed.

for i in list:
    try:
        print(i/10)
    except:
        print("Error")
0.1
0.2
0.3
0.4
Error
0.5
0.6

I did well.

Recommended Posts

Python, about exception handling
Python exception handling
Python exception handling (Python learning memo ⑥)
Exception handling
Exception handling during Python API communication
About python slices
About python yield
About python, class
Python Error Handling
boto3 exception handling
About python decorators
Python timezone handling
About python reference
About Python decorators
[Python] About multi-process
I tried to summarize Python exception handling
[Introduction to Udemy Python3 + Application] 65. Exception handling
Python exception handling a little more convenient
Module import and exception handling in python
About Python for loops
Summary about Python scraping
About function arguments (python)
Handling yaml with python
About tweepy error handling
Handling json in python
Exception message in Python
[Python] Memo about functions
Summary about Python3 + OpenCV3
About Python, for ~ (range)
About Python3 character code
[Python] Memo about errors
About Python development environment
Python: About function arguments
Python decimal point handling
Hexadecimal handling in Python 3
About Python Pyramid traversal
About Python3 ... (Ellipsis object)
[Python] Chapter 01-01 About Python (First Python)
[Python] About standard input
About __all__ in python
Python exception class list
Fizzbuzz with exception handling
[Python for Hikari-] Chapter 07-01 Exception Handling (Errors and Exceptions)
[Python] Find out about pip
About FastAPI ~ Endpoint error handling ~
About Fabric's support for Python 3
About python objects and classes
About Python variables and objects
About the Python module venv
About python beginner's memorandum function
About the ease of Python
About the enumerate function (python)
Exception handling using Python's ZeroDivisionError
About various encodings of Python 3
python> Handling of 2D arrays
Handling of python on mac
About Perl, Python, PHP, Ruby
About Python datetime and timezone
A memorandum about correlation [Python]
A memorandum about Python mock
About Python string comparison operators