ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.2 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://tutorial.eyehunts.com/python/python-print-exception-message/ |
| Last Crawled | 2026-04-12 14:01:44 (4 days ago) |
| First Indexed | 2022-12-30 03:48:53 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Python Print exception message |
| Meta Description | The most common method to catch and print the exception message in Python is using try-except statements. If You want to save an error... |
| Meta Canonical | null |
| Boilerpipe Text | The most common method to catch and print the exception message in Python is using
try-except
statements. If You want to save an error message then use the
logger.exception()
method.
This method produces an error message as well as a log trace. It contains information such as the code line number at which the exception occurred and the time the exception occurred.
Simple example code catch and
prints
The Exception Messages In Python.
list_arr = [10, 20, 30, "5f", "7k", 78, 88]
for elem in list_arr:
try:
print("Result: ", elem / 9)
except Exception as e:
print("Exception occurred for value '" + elem + "': " + repr(e))
Output:
Using try and logger.exception to print an error message
import logging
logger = logging.getLogger()
num1 = 1
num2 = 0
try:
print("Result: ", num1 / num2)
except Exception as e:
logger.exception("Exception Occured while code Execution: " + str(e))
Output:
Exception Occured while code Execution: division by zero
Traceback (most recent call last):
File "C:\Users\Rohit\PycharmProjects\pythonProject\modules\main.py", line 9, in <module>
print("Result: ", num1 / num2)
ZeroDivisionError: division by zero
Do comment if you have any doubts or suggestions on this
Python exception-handling
topic.
Note:
IDE:
PyCharm
2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All
Python Examples are in Python 3
, so Maybe its different from python 2 or upgraded versions. |
| Markdown | [Skip to content](https://tutorial.eyehunts.com/python/python-print-exception-message/#content)
[Tutorial By EyeHunts](https://tutorial.eyehunts.com/)
- [EyeHunts.com](https://eyehunts.com/)
- [Java](https://tutorial.eyehunts.com/java-tutorial/)
- [Python](https://tutorial.eyehunts.com/python-tutorial/)
- [Android](https://tutorial.eyehunts.com/android-tutorial/)
- [Tutorial](https://tutorial.eyehunts.com/)
- [Andriod](https://tutorial.eyehunts.com/android-tutorial/)
- [JAVA](https://tutorial.eyehunts.com/java-tutorial)
- [Python](https://tutorial.eyehunts.com/python-tutorial/)
- [Contact US](https://eyehunts.com/contact-us/)
- [Interview Puzzle](https://tutorial.eyehunts.com/top-interview-puzzle-questions-for-software-developers/)
[Tutorial By EyeHunts](https://tutorial.eyehunts.com/)
Navigation Menu
Navigation Menu
- [EyeHunts.com](https://eyehunts.com/)
- [Java](https://tutorial.eyehunts.com/java-tutorial/)
- [Python](https://tutorial.eyehunts.com/python-tutorial/)
- [Android](https://tutorial.eyehunts.com/android-tutorial/)
- [Tutorial](https://tutorial.eyehunts.com/)
- [Andriod](https://tutorial.eyehunts.com/android-tutorial/)
- [JAVA](https://tutorial.eyehunts.com/java-tutorial)
- [Python](https://tutorial.eyehunts.com/python-tutorial/)
- [Contact US](https://eyehunts.com/contact-us/)
- [Interview Puzzle](https://tutorial.eyehunts.com/top-interview-puzzle-questions-for-software-developers/)
# Python Print exception message
- by [Rohit](https://tutorial.eyehunts.com/author/rohit/ "Posts by Rohit")
- December 30, 2022
The most common method to catch and print the exception message in Python is using [try-except](https://tutorial.eyehunts.com/python/nested-try-except-python/) statements. If You want to save an error message then use the **logger.exception()** method.
This method produces an error message as well as a log trace. It contains information such as the code line number at which the exception occurred and the time the exception occurred.
## **Python Print exception**
Simple example code catch and [prints](https://tutorial.eyehunts.com/python/python-printf-string/) The Exception Messages In Python.
```
list_arr = [10, 20, 30, "5f", "7k", 78, 88]
for elem in list_arr:
try:
print("Result: ", elem / 9)
except Exception as e:
print("Exception occurred for value '" + elem + "': " + repr(e))
```
**Output:**

**Using try and logger.exception to print an error message**
```
import logging
logger = logging.getLogger()
num1 = 1
num2 = 0
try:
print("Result: ", num1 / num2)
except Exception as e:
logger.exception("Exception Occured while code Execution: " + str(e))
```
**Output:**
```
Exception Occured while code Execution: division by zero
Traceback (most recent call last):
File "C:\Users\Rohit\PycharmProjects\pythonProject\modules\main.py", line 9, in <module>
print("Result: ", num1 / num2)
ZeroDivisionError: division by zero
```
Do comment if you have any doubts or suggestions on this [Python exception-handling](https://tutorial.eyehunts.com/python/python-throw-exception/) topic.
> **Note:** IDE: [PyCharm](https://www.jetbrains.com/pycharm/) 2021.3.3 (Community Edition)
>
> Windows 10
>
> **Python 3.10.1**
>
> All **Python Examples are in Python 3**, so Maybe its different from python 2 or upgraded versions.
### Share this:
- [Click to share on Facebook (Opens in new window) Facebook](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=facebook)
- [Click to share on WhatsApp (Opens in new window) WhatsApp](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=jetpack-whatsapp)
- [Click to share on LinkedIn (Opens in new window) LinkedIn](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=linkedin)
- [More](https://tutorial.eyehunts.com/python/python-print-exception-message/)
- [Click to share on X (Opens in new window) X](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=twitter)
- [Click to print (Opens in new window) Print](https://tutorial.eyehunts.com/python/python-print-exception-message/#print?share=print)
- [Click to share on Reddit (Opens in new window) Reddit](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=reddit)
- [Click to share on Tumblr (Opens in new window) Tumblr](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=tumblr)
- [Click to share on Pinterest (Opens in new window) Pinterest](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=pinterest)
- [Click to share on Pocket (Opens in new window) Pocket](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=pocket)
- [Click to share on Telegram (Opens in new window) Telegram](https://tutorial.eyehunts.com/python/python-print-exception-message/?share=telegram)
- [Click to email a link to a friend (Opens in new window) Email](https://tutorial.eyehunts.com/cdn-cgi/l/email-protection#e7d89492858d828493dac2d2a5b48f86958283c2d5d7b7889493c2d2a3c2d5d7b79e938f8889c2d5d7b7958e8993c2d5d7829f848297938e8889c2d5d78a829494868082c1c4d7d4dfdc8588839eda8f93939794c2d4a6c2d5a1c2d5a193929388958e868bc9829e828f92899394c984888ac2d5a1979e938f8889c2d5a1979e938f8889ca97958e8993ca829f848297938e8889ca8a829494868082c2d5a1c1c4d7d4dfdc948f869582da828a868e8b)
### *Related*
Tags:[Python exception](https://tutorial.eyehunts.com/tag/python-exception/ "Python exception")[Python Print](https://tutorial.eyehunts.com/tag/python-print/ "Python Print")
## Leave a Reply [Cancel reply](https://tutorial.eyehunts.com/python/python-print-exception-message/#respond)
You must be [logged in](https://tutorial.eyehunts.com/shro/?redirect_to=https%3A%2F%2Ftutorial.eyehunts.com%2Fpython%2Fpython-print-exception-message%2F) to post a comment.
Recent Posts
- [Window Memes](https://tutorial.eyehunts.com/memes/window-memes/)
- [Windows memes](https://tutorial.eyehunts.com/java/windows-memes/)
- [Github Memes](https://tutorial.eyehunts.com/memes/github-memes/)
- [Linux memes](https://tutorial.eyehunts.com/memes/linux-memes/)
- [JavaScript const keyword \| Basics](https://tutorial.eyehunts.com/js/javascript-const-keyword-basics/)
Categories
- [Android](https://tutorial.eyehunts.com/category/android/)
- [Android Interview Questions](https://tutorial.eyehunts.com/category/android-interview-questions/)
- [Android Kotlin](https://tutorial.eyehunts.com/category/kotlin-android/)
- [Android UI](https://tutorial.eyehunts.com/category/android-ui/)
- [C](https://tutorial.eyehunts.com/category/c/)
- [CSS](https://tutorial.eyehunts.com/category/css/)
- [Data structure](https://tutorial.eyehunts.com/category/data-structures/)
- [HTML](https://tutorial.eyehunts.com/category/html/)
- [Info](https://tutorial.eyehunts.com/category/info/)
- [Java](https://tutorial.eyehunts.com/category/java/)
- [JavaScript](https://tutorial.eyehunts.com/category/js/)
- [jQuery](https://tutorial.eyehunts.com/category/jquery/)
- [JSON](https://tutorial.eyehunts.com/category/json/)
- [Kotlin](https://tutorial.eyehunts.com/category/kotlin/)
- [Material Design](https://tutorial.eyehunts.com/category/android/material-design/)
- [Memes](https://tutorial.eyehunts.com/category/memes/)
- [NodeJS](https://tutorial.eyehunts.com/category/nodejs/)
- [Puzzle](https://tutorial.eyehunts.com/category/puzzle/)
- [Python](https://tutorial.eyehunts.com/category/python/)
- [SQL](https://tutorial.eyehunts.com/category/sql/)
- [Tool](https://tutorial.eyehunts.com/category/tool/)
- [TypeScript](https://tutorial.eyehunts.com/category/typescript/)
Search Topics
Archives
Archives
Subscribe
Copyright © 2014 EyeHunts.com. All Rights Reserved
[© 2014 EyeHunts. All rights reserved](https://eyehunts.com/)
Copyright © 2014 EyeHunts.com. All Rights Reserved
[© 2014 EyeHunts. All rights reserved](https://eyehunts.com/)
## Discover more from Tutorial
Subscribe now to keep reading and get access to the full archive.
[Continue reading](https://tutorial.eyehunts.com/python/python-print-exception-message/) |
| Readable Markdown | The most common method to catch and print the exception message in Python is using [try-except](https://tutorial.eyehunts.com/python/nested-try-except-python/) statements. If You want to save an error message then use the **logger.exception()** method.
This method produces an error message as well as a log trace. It contains information such as the code line number at which the exception occurred and the time the exception occurred.
Simple example code catch and [prints](https://tutorial.eyehunts.com/python/python-printf-string/) The Exception Messages In Python.
```
list_arr = [10, 20, 30, "5f", "7k", 78, 88]
for elem in list_arr:
try:
print("Result: ", elem / 9)
except Exception as e:
print("Exception occurred for value '" + elem + "': " + repr(e))
```
**Output:**

**Using try and logger.exception to print an error message**
```
import logging
logger = logging.getLogger()
num1 = 1
num2 = 0
try:
print("Result: ", num1 / num2)
except Exception as e:
logger.exception("Exception Occured while code Execution: " + str(e))
```
**Output:**
```
Exception Occured while code Execution: division by zero
Traceback (most recent call last):
File "C:\Users\Rohit\PycharmProjects\pythonProject\modules\main.py", line 9, in <module>
print("Result: ", num1 / num2)
ZeroDivisionError: division by zero
```
Do comment if you have any doubts or suggestions on this [Python exception-handling](https://tutorial.eyehunts.com/python/python-throw-exception/) topic.
> **Note:** IDE: [PyCharm](https://www.jetbrains.com/pycharm/) 2021.3.3 (Community Edition)
>
> Windows 10
>
> **Python 3.10.1**
>
> All **Python Examples are in Python 3**, so Maybe its different from python 2 or upgraded versions. |
| Shard | 55 (laksa) |
| Root Hash | 9754410218282928255 |
| Unparsed URL | com,eyehunts!tutorial,/python/python-print-exception-message/ s443 |