šŸ•·ļø Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 121 (from laksa150)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ā„¹ļø Skipped - page is already crawled

šŸ“„
INDEXABLE
āœ…
CRAWLED
2 days ago
šŸ¤–
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://blog.finxter.com/how-to-print-the-exception-without-exiting-your-python-program/
Last Crawled2026-04-09 21:42:22 (2 days ago)
First Indexed2021-08-08 11:59:33 (4 years ago)
HTTP Status Code200
Meta TitleHow to Print the Exception Without Exiting Your Python Program? - Be on the Right Side of Change
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
Problem Formulation Given a basic Python program. How to print an exception if it occurs without exiting the program? For example, consider the following program that raises a ZeroDivisionError: division by zero . x = 42/0 print('Program is still running') The output is: Traceback (most recent call last): File "C:\Users\xcent\Desktop\code.py", line 1, in <module> x = 42/0 ZeroDivisionError: division by zero You want the program to keep running and executing the print statement after giving you a note about the exception: division by zero Program is still running How to accomplish this in Python? Basic Solution: Try/Except An exception will immediately terminate your program. To avoid this, you can catch the exception with a try/except block around the code where you expect that a certain exception may occur. Here’s how you catch and print a given exception: To catch and print an exception that occurred in a code snippet, wrap it in an indented try block, followed by the command "except Exception as e" that catches the exception and saves its error message in string variable e . You can now print the error message with "print(e)" or use it for further processing. Here’s the general exception handling framework : try: # ... YOUR CODE HERE ... # except Exception as e: # ... PRINT THE ERROR MESSAGE ... # print(e) In our particular example, you’d modify your program from … x = 42/0 print('Program is still running') … to … try: x = 42/0 except Exception as e: print(e) print('Program is still running') Now, the output is your desired: division by zero Program is still running Full Traceback Error Message To print the full traceback of the error message—and keep the program running without exiting on an error—you can use a try/except block in combination with the traceback module’s format_exc() function. Import the module with import traceback . Print the full traceback of the error with print(traceback.format_exc()) . Here’s the full example code: import traceback import sys try: x = 42/0 except Exception: print(traceback.format_exc()) print('Program is still running') Now, the output shows the full traceback like so: Traceback (most recent call last): File "C:\Users\xcent\Desktop\code.py", line 5, in <module> x = 42/0 ZeroDivisionError: division by zero Program is still running The last line shows that the program doesn’t terminate when the exception occurs. šŸ§‘ā€šŸ’» Recommended : Python Print Exception: 13 Easy Ways to Try-Except-Print Errors for Beginners Summary To print an exception without exiting the program, use a try/except block and assign the exception object to variable e using except Exception as e . Now, call print(e) in the except branch to print a simple error message. If you need a more advanced error message with full traceback, import the traceback module and call print(traceback.format_exc()) in the except branch. Where to Go From Here? Enough theory. Let’s get some practice! Coders get paid six figures and more because they can solve problems more effectively using machine intelligence and automation. To become more successful in coding, solve more real problems for real people. That’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs? You build high-value coding skills by working on practical coding projects! Do you want to stop learning with toy projects and focus on practical code projects that earn you money and solve real problems for people? šŸš€ If your answer is YES! , consider becoming a Python freelance developer ! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner. If you just want to learn about the freelancing opportunity, feel free to watch my free webinar ā€œHow to Build Your High-Income Skill Pythonā€ and learn how I grew my coding business online and how you can, too—from the comfort of your own home. Join the free webinar now!
Markdown
[Skip to content](https://blog.finxter.com/how-to-print-the-exception-without-exiting-your-python-program/#content "Skip to content") [![Be on the Right Side of Change](https://blog.finxter.com/wp-content/uploads/2020/08/cropped-cropped-finxter_nobackground-1.png)](https://blog.finxter.com/) Menu - [šŸ”“ YouTube](https://www.youtube.com/@finxter) - [šŸ‘‘ Membership](https://blog.finxter.com/finxter-premium-membership/) - [šŸ‘©ā€šŸŽ“ Academy](https://academy.finxter.com/) - [šŸ“– Books](https://blog.finxter.com/finxter-books/) - [šŸŽ² Puzzles](https://app.finxter.com/learn/computer/science/) - [šŸ¤Ž User Stories](https://blog.finxter.com/what-our-users-say/) - [What Our Users Say](https://blog.finxter.com/what-our-users-say/) - [About Finxter](https://blog.finxter.com/about/) - [Finxter Feedback from ~1000 Python Developers](https://blog.finxter.com/finxter-feedback-from-1000-users/) - [Video Reviews](https://blog.finxter.com/python-freelancer-course-testimonials-from-finxters/) - [Course Review from Cristian](https://blog.finxter.com/finxter-review-become-a-freelancer-course/?tl_inbound=1&tl_target_all=1&tl_form_type=1&tl_period_type=3) - [Course Review from Adam](https://blog.finxter.com/how-adam-earns-5000-per-month-as-a-python-freelancer-on-upwork-month-4/) - [Review by ChatGPT](https://blog.finxter.com/what-is-finxter-is-it-trustworthy-chatgpt-answers/) - [About Chris](https://blog.finxter.com/about-chris/) - [Start Here ⭐](https://blog.finxter.com/make-money-ai/) # How to Print the Exception Without Exiting Your Python Program? October 11, 2023 August 8, 2021 by [Chris](https://blog.finxter.com/author/xcentpy_cfsh849y/ "View all posts by Chris") ## Problem Formulation Given a basic Python program. How to [print](https://blog.finxter.com/python-print/ "Python print()") an exception if it occurs without exiting the program? For example, consider the following program that raises a `ZeroDivisionError: division by zero`. ``` x = 42/0 print('Program is still running') ``` The output is: ``` Traceback (most recent call last): File "C:\Users\xcent\Desktop\code.py", line 1, in <module> x = 42/0 ZeroDivisionError: division by zero ``` You want the program to keep running and executing the print statement after giving you a note about the exception: ``` division by zero Program is still running ``` How to accomplish this in Python? ## Basic Solution: Try/Except An exception will immediately terminate your program. To avoid this, you can **catch the exception** with a `try/except` block around the code where you expect that a certain exception may occur. Here’s how you **catch and print a given exception:** To catch and print an exception that occurred in a code snippet, wrap it in an indented `try` block, followed by the command `"except Exception as e"` that catches the exception and saves its error message in string variable `e`. You can now print the error message with `"print(e)"` or use it for further processing. Here’s the general *exception handling framework*: ``` try: # ... YOUR CODE HERE ... # except Exception as e: # ... PRINT THE ERROR MESSAGE ... # print(e) ``` In our particular example, you’d modify your program from … ``` x = 42/0 print('Program is still running') ``` … to … ``` try: x = 42/0 except Exception as e: print(e) print('Program is still running') ``` Now, the output is your desired: ``` division by zero Program is still running ``` ## Full Traceback Error Message To print the full traceback of the error message—and keep the program running without exiting on an error—you can use a try/except block in combination with the `traceback` module’s `format_exc()` function. - Import the module with `import traceback`. - Print the full traceback of the error with `print(traceback.format_exc())`. Here’s the full example code: ``` import traceback import sys try: x = 42/0 except Exception: print(traceback.format_exc()) print('Program is still running') ``` Now, the output shows the full traceback like so: ``` Traceback (most recent call last): File "C:\Users\xcent\Desktop\code.py", line 5, in <module> x = 42/0 ZeroDivisionError: division by zero Program is still running ``` The last line shows that the program doesn’t [terminate](https://blog.finxter.com/difference-between-exit-and-sys-exit-in-python/ "Difference Between exit() and sys.exit() in Python") when the exception occurs. šŸ§‘ā€šŸ’» **Recommended**: [Python Print Exception: 13 Easy Ways to Try-Except-Print Errors for Beginners](https://blog.finxter.com/how-to-catch-and-print-exception-messages-in-python/) ## Summary To print an exception without exiting the program, use a try/except block and assign the exception object to variable `e` using `except Exception as e`. Now, call `print(e)` in the `except` branch to print a simple error message. If you need a more advanced error message with full traceback, import the `traceback` module and call `print(traceback.format_exc())` in the `except` branch. ## Where to Go From Here? Enough theory. Let’s get some practice\! Coders get paid six figures and more because they can solve problems more effectively using machine intelligence and automation. To become more successful in coding, solve more real problems for real people. That’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs? **You build high-value coding skills by working on practical coding projects\!** Do you want to stop learning with toy projects and focus on practical code projects that earn you money and solve real problems for people? šŸš€ If your answer is ***YES\!***, consider becoming a [Python freelance developer](https://blog.finxter.com/become-python-freelancer-course/)! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner. If you just want to learn about the freelancing opportunity, feel free to watch my free webinar [ā€œHow to Build Your High-Income Skill Pythonā€](https://blog.finxter.com/webinar-freelancer/) and learn how I grew my coding business online and how you can, too—from the comfort of your own home. [Join the free webinar now\!](https://blog.finxter.com/webinar-freelancer/) Categories [Error](https://blog.finxter.com/category/error/), [Exception Handling](https://blog.finxter.com/category/exception-handling/), [Python](https://blog.finxter.com/category/python/) [How to Find the Index of an Element in a List of Lists?](https://blog.finxter.com/how-to-find-the-index-of-an-element-in-a-list-of-lists/) [3 Little-Known NumPy Tricks in One Line \[Python Puzzle\]](https://blog.finxter.com/3-little-known-numpy-tricks-in-one-line-python-puzzle/) **Be on the Right Side of Change** šŸš€ The world is changing exponentially. AI eliminates entire industries. ![šŸ¤–](https://s.w.org/images/core/emoji/17.0.2/svg/1f916.svg) ![šŸ’°](https://s.w.org/images/core/emoji/17.0.2/svg/1f4b0.svg) [12 Ways to Make Money with AI](https://blog.finxter.com/make-money-ai/) (Article) **![⭐](https://s.w.org/images/core/emoji/17.0.2/svg/2b50.svg) [Join our free email newsletter](https://blog.finxter.com/ai/) (130k subs).** Be on the right side of change with AI and master the art of vibe coding! ![🌓](https://s.w.org/images/core/emoji/17.0.2/svg/1f334.svg) **New Finxter Tutorials:** - [What to Code (Book): How Indie Hackers Find Million-Dollar Micro-SaaS Ideas in the Vibe Coding Era](https://blog.finxter.com/what-to-code-book-how-indie-hackers-find-million-dollar-micro-saas-ideas-in-the-vibe-coding-era/) - [6 Best AI Book Writers (2026): Tools for Authors & Self-Publishers](https://blog.finxter.com/best-ai-book-writers/) - [What Your Last 10 YouTube Videos Say About Your Future Business](https://blog.finxter.com/what-your-last-10-youtube-videos-say-about-your-future-business/) - [\[Free eBook\] Automate the Boring Stuff and Make Money with Clawdbot](https://blog.finxter.com/free-ebook-automate-the-boring-stuff-and-make-money-with-clawdbot/) - [The JSON Trick – How to Scrape All Answers in a Subreddit? (Example Find User Needs)](https://blog.finxter.com/the-json-trick-how-to-scrape-all-answers-in-a-subreddit-example-find-user-needs/) - [The Ghost Founder: 10 AI Startups That Can Hit \$1B Without a Single Employee](https://blog.finxter.com/the-ghost-founder-10-ai-startups-that-can-hit-1b-without-a-single-employee/) - [Stop Testing LLMs with Poetry: Use Blackjack Instead](https://blog.finxter.com/stop-testing-llms-with-poetry-use-blackjack-instead/) - [The ā€œOne Niche, One Channelā€ rule for making your first \$1k in AI](https://blog.finxter.com/the-one-niche-one-channel-rule-for-making-your-first-1k-in-ai/) - [Dreaming of the Mediterranean: When Will Tesla FSD Hit Europe?](https://blog.finxter.com/dreaming-of-the-mediterranean-when-will-tesla-fsd-hit-europe/) - [DriftIDE – A Startup Idea for 1B Vibe Coders \[Pitch Deck\]](https://blog.finxter.com/driftide-a-startup-idea-for-1b-vibe-coders-pitch-deck/) **Finxter Categories:** Categories - [About](https://blog.finxter.com/about/) - [Impressum](https://app.finxter.com/impressum) - [Privacy](https://blog.finxter.com/privacy-policy/) - [Terms](https://blog.finxter.com/terms-and-conditions-of-use/) - [Puzzles](https://app.finxter.com/) - [Academy](https://academy.finxter.com/) - [Books & Courses](https://blog.finxter.com/) - [Earnings Disclaimer](https://blog.finxter.com/earnings-disclaimer/) - [Finxter Instagram](https://www.instagram.com/finxterdotcom/) - [Finxter Twitter](https://twitter.com/FinxterDotCom) - [Finxter Facebook](https://www.facebook.com/finxter) - [Finxter YouTube](https://www.youtube.com/@finxter) - [šŸ”“ YouTube](https://www.youtube.com/@finxter) - [šŸ‘‘ Membership](https://blog.finxter.com/finxter-premium-membership/) - [šŸ‘©ā€šŸŽ“ Academy](https://academy.finxter.com/) - [šŸ“– Books](https://blog.finxter.com/finxter-books/) - [šŸŽ² Puzzles](https://app.finxter.com/learn/computer/science/) - [šŸ¤Ž User Stories](https://blog.finxter.com/what-our-users-say/) - [What Our Users Say](https://blog.finxter.com/what-our-users-say/) - [About Finxter](https://blog.finxter.com/about/) - [Finxter Feedback from ~1000 Python Developers](https://blog.finxter.com/finxter-feedback-from-1000-users/) - [Video Reviews](https://blog.finxter.com/python-freelancer-course-testimonials-from-finxters/) - [Course Review from Cristian](https://blog.finxter.com/finxter-review-become-a-freelancer-course/?tl_inbound=1&tl_target_all=1&tl_form_type=1&tl_period_type=3) - [Course Review from Adam](https://blog.finxter.com/how-adam-earns-5000-per-month-as-a-python-freelancer-on-upwork-month-4/) - [Review by ChatGPT](https://blog.finxter.com/what-is-finxter-is-it-trustworthy-chatgpt-answers/) - [About Chris](https://blog.finxter.com/about-chris/) - [Start Here ⭐](https://blog.finxter.com/make-money-ai/) Ā© 2026 Be on the Right Side of Change • Built with [GeneratePress](https://generatepress.com/)
Readable Markdown
## Problem Formulation Given a basic Python program. How to [print](https://blog.finxter.com/python-print/ "Python print()") an exception if it occurs without exiting the program? For example, consider the following program that raises a `ZeroDivisionError: division by zero`. ``` x = 42/0 print('Program is still running') ``` The output is: ``` Traceback (most recent call last): File "C:\Users\xcent\Desktop\code.py", line 1, in <module> x = 42/0 ZeroDivisionError: division by zero ``` You want the program to keep running and executing the print statement after giving you a note about the exception: ``` division by zero Program is still running ``` How to accomplish this in Python? ## Basic Solution: Try/Except An exception will immediately terminate your program. To avoid this, you can **catch the exception** with a `try/except` block around the code where you expect that a certain exception may occur. Here’s how you **catch and print a given exception:** To catch and print an exception that occurred in a code snippet, wrap it in an indented `try` block, followed by the command `"except Exception as e"` that catches the exception and saves its error message in string variable `e`. You can now print the error message with `"print(e)"` or use it for further processing. Here’s the general *exception handling framework*: ``` try: # ... YOUR CODE HERE ... # except Exception as e: # ... PRINT THE ERROR MESSAGE ... # print(e) ``` In our particular example, you’d modify your program from … ``` x = 42/0 print('Program is still running') ``` … to … ``` try: x = 42/0 except Exception as e: print(e) print('Program is still running') ``` Now, the output is your desired: ``` division by zero Program is still running ``` ## Full Traceback Error Message To print the full traceback of the error message—and keep the program running without exiting on an error—you can use a try/except block in combination with the `traceback` module’s `format_exc()` function. - Import the module with `import traceback`. - Print the full traceback of the error with `print(traceback.format_exc())`. Here’s the full example code: ``` import traceback import sys try: x = 42/0 except Exception: print(traceback.format_exc()) print('Program is still running') ``` Now, the output shows the full traceback like so: ``` Traceback (most recent call last): File "C:\Users\xcent\Desktop\code.py", line 5, in <module> x = 42/0 ZeroDivisionError: division by zero Program is still running ``` The last line shows that the program doesn’t [terminate](https://blog.finxter.com/difference-between-exit-and-sys-exit-in-python/ "Difference Between exit() and sys.exit() in Python") when the exception occurs. šŸ§‘ā€šŸ’» **Recommended**: [Python Print Exception: 13 Easy Ways to Try-Except-Print Errors for Beginners](https://blog.finxter.com/how-to-catch-and-print-exception-messages-in-python/) ## Summary To print an exception without exiting the program, use a try/except block and assign the exception object to variable `e` using `except Exception as e`. Now, call `print(e)` in the `except` branch to print a simple error message. If you need a more advanced error message with full traceback, import the `traceback` module and call `print(traceback.format_exc())` in the `except` branch. ## Where to Go From Here? Enough theory. Let’s get some practice\! Coders get paid six figures and more because they can solve problems more effectively using machine intelligence and automation. To become more successful in coding, solve more real problems for real people. That’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs? **You build high-value coding skills by working on practical coding projects\!** Do you want to stop learning with toy projects and focus on practical code projects that earn you money and solve real problems for people? šŸš€ If your answer is ***YES\!***, consider becoming a [Python freelance developer](https://blog.finxter.com/become-python-freelancer-course/)! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner. If you just want to learn about the freelancing opportunity, feel free to watch my free webinar [ā€œHow to Build Your High-Income Skill Pythonā€](https://blog.finxter.com/webinar-freelancer/) and learn how I grew my coding business online and how you can, too—from the comfort of your own home. [Join the free webinar now\!](https://blog.finxter.com/webinar-freelancer/)
Shard121 (laksa)
Root Hash6977083233833885521
Unparsed URLcom,finxter!blog,/how-to-print-the-exception-without-exiting-your-python-program/ s443