🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 169 (from laksa176)

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
5 months ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH5.9 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://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python
Last Crawled2025-10-18 06:56:10 (5 months ago)
First Indexed2022-06-20 07:53:14 (3 years ago)
HTTP Status Code200
Meta TitleHow do I print an exception in Python? - Stack Overflow
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
(I was going to leave this as a comment on @jldupont's answer , but I don't have enough reputation.) I've seen answers like @jldupont's answer in other places as well. FWIW, I think it's important to note that this: except Exception as e: print (e) will print the error output to sys.stdout by default. A more appropriate approach to error handling in general would be: except Exception as e: print (e, file=sys.stderr) (Note that you have to import sys for this to work.) This way, the error is printed to STDERR instead of STDOUT , which allows for the proper output parsing/redirection/etc. I understand that the question was strictly about 'printing an error', but it seems important to point out the best practice here rather than leave out this detail that could lead to non-standard code for anyone who doesn't eventually learn better. I haven't used the traceback module as in Cat Plus Plus's answer , and maybe that's the best way, but I thought I'd throw this out there.
Markdown
# ![site logo](https://stackoverflow.com/Content/Img/SE-logo75.png) By clicking “Sign up”, you agree to our [terms of service](https://stackoverflow.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://stackoverflow.com/legal/privacy-policy). # OR Already have an account? [Log in](https://stackoverflow.com/users/login) [Skip to main content](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#content) [Stack Overflow](https://stackoverflow.com/) 1. [About](https://stackoverflow.co/) 2. Products 3. [For Teams](https://stackoverflow.co/teams/) 1. [Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-for-teams) 2. [Advertising Reach devs & technologists worldwide about your product, service or employer brand](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-advertising) 3. [Knowledge Solutions Data licensing offering for businesses to build and improve AI tools and models](https://stackoverflow.co/api-solutions/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=overflow-api) 4. [Labs The future of collective knowledge sharing](https://stackoverflow.co/labs/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=labs) 5. [About the company](https://stackoverflow.co/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=about-the-company) [Visit the blog](https://stackoverflow.blog/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=blog) 1. ### [current community](https://stackoverflow.com/) - [Stack Overflow](https://stackoverflow.com/) [help](https://stackoverflow.com/help) [chat](https://chat.stackoverflow.com/?tab=explore) - [Meta Stack Overflow](https://meta.stackoverflow.com/) ### your communities [Sign up](https://stackoverflow.com/users/signup?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1483429%2Fhow-do-i-print-an-exception-in-python) or [log in](https://stackoverflow.com/users/login?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1483429%2Fhow-do-i-print-an-exception-in-python) to customize your list. ### [more stack exchange communities](https://stackexchange.com/sites) [company blog](https://stackoverflow.blog/) 2. [Log in](https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1483429%2Fhow-do-i-print-an-exception-in-python) 3. [Sign up](https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1483429%2Fhow-do-i-print-an-exception-in-python) Shape the future of the Stack Exchange API - [get early access to what’s new](https://research.rallyuxr.com/stack_overflow/lp/cmfpej0pr1rzfhvmo1a421lon?channel=share&signupFormId=cmfpej0pr1rzehvmo8v2ufio0)\! # Let's set up your homepage Select a few topics you're interested in: python javascript c\# reactjs java android html flutter c++ node.js typescript css r php angular next.js spring-boot machine-learning sql excel ios azure docker Or search from our full list: - javascript - python - java - c\# - php - android - html - jquery - c++ - css - ios - sql - mysql - r - reactjs - node.js - arrays - c - asp.net - json - python-3.x - .net - ruby-on-rails - sql-server - swift - django - angular - objective-c - excel - pandas - angularjs - regex - typescript - ruby - linux - ajax - iphone - vba - xml - laravel - spring - asp.net-mvc - database - wordpress - string - flutter - postgresql - mongodb - wpf - windows - xcode - amazon-web-services - bash - git - oracle-database - spring-boot - dataframe - azure - firebase - list - multithreading - docker - vb.net - react-native - eclipse - algorithm - powershell - macos - visual-studio - numpy - image - forms - scala - function - vue.js - performance - twitter-bootstrap - selenium - winforms - kotlin - loops - express - dart - hibernate - sqlite - matlab - python-2.7 - shell - rest - apache - entity-framework - android-studio - csv - maven - linq - qt - dictionary - unit-testing - asp.net-core - facebook - apache-spark - tensorflow - file - swing - class - unity-game-engine - sorting - date - authentication - go - symfony - t-sql - opencv - matplotlib - .htaccess - google-chrome - for-loop - datetime - codeigniter - perl - http - validation - sockets - google-maps - object - uitableview - xaml - oop - visual-studio-code - if-statement - cordova - ubuntu - web-services - email - android-layout - github - spring-mvc - elasticsearch - kubernetes - selenium-webdriver - ms-access - ggplot2 - user-interface - parsing - pointers - c++11 - google-sheets - security - machine-learning - google-apps-script - ruby-on-rails-3 - templates - flask - nginx - variables - exception - sql-server-2008 - gradle - debugging - tkinter - delphi - listview - jpa - asynchronous - web-scraping - haskell - pdf - jsp - ssl - amazon-s3 - google-cloud-platform - jenkins - testing - xamarin - wcf - batch-file - generics - npm - ionic-framework - network-programming - unix - recursion - google-app-engine - mongoose - visual-studio-2010 - .net-core - android-fragments - assembly - animation - math - svg - session - rust - intellij-idea - hadoop - next.js - curl - join - winapi - django-models - laravel-5 - url - heroku - http-redirect - tomcat - google-cloud-firestore - inheritance - webpack - image-processing - gcc - keras - swiftui - asp.net-mvc-4 - logging - dom - matrix - pyspark - actionscript-3 - button - post - optimization - firebase-realtime-database - web - jquery-ui - cocoa - xpath - iis - d3.js - javafx - firefox - xslt - internet-explorer - caching - select - asp.net-mvc-3 - opengl - events - asp.net-web-api - plot - dplyr - encryption - magento - stored-procedures - search - amazon-ec2 - ruby-on-rails-4 - memory - canvas - audio - multidimensional-array - random - jsf - vector - redux - cookies - input - facebook-graph-api - flash - indexing - xamarin.forms - arraylist - ipad - cocoa-touch - data-structures - video - azure-devops - model-view-controller - apache-kafka - serialization - jdbc - woocommerce - razor - routes - awk - servlets - mod-rewrite - excel-formula - beautifulsoup - filter - docker-compose - iframe - aws-lambda - design-patterns - text - visual-c++ - django-rest-framework - cakephp - mobile - android-intent - struct - react-hooks - methods - groovy - mvvm - ssh - lambda - checkbox - time - ecmascript-6 - grails - google-chrome-extension - installation - cmake - sharepoint - shiny - spring-security - jakarta-ee - plsql - android-recyclerview - core-data - types - sed - meteor - android-activity - activerecord - bootstrap-4 - websocket - graph - replace - scikit-learn - group-by - vim - file-upload - junit - boost - memory-management - sass - import - deep-learning - async-await - error-handling - eloquent - dynamic - soap - dependency-injection - silverlight - layout - apache-spark-sql - charts - deployment - browser - gridview - svn - while-loop - google-bigquery - vuejs2 - highcharts - dll - ffmpeg - view - foreach - makefile - plugins - redis - c\#-4.0 - reporting-services - jupyter-notebook - unicode - merge - reflection - https - server - google-maps-api-3 - twitter - oauth-2.0 - extjs - terminal - axios - pip - split - cmd - pytorch - encoding - django-views - collections - database-design - hash - netbeans - automation - data-binding - ember.js - build - tcp - pdo - sqlalchemy - apache-flex - mysqli - entity-framework-core - concurrency - command-line - spring-data-jpa - printing - react-redux - java-8 - lua - html-table - ansible - jestjs - neo4j - service - parameters - material-ui - enums - flexbox - module - promise - visual-studio-2012 - outlook - firebase-authentication - web-applications - webview - uwp - jquery-mobile - utf-8 - datatable - python-requests - parallel-processing - colors - drop-down-menu - scipy - scroll - tfs - hive - count - syntax - ms-word - twitter-bootstrap-3 - ssis - fonts - rxjs - constructor - google-analytics - file-io - three.js - paypal - powerbi - graphql - cassandra - discord - graphics - compiler-errors - gwt - socket.io - react-router - solr - backbone.js - memory-leaks - url-rewriting - datatables - nlp - oauth - terraform - datagridview - drupal - oracle11g - zend-framework - knockout.js - triggers - neural-network - interface - django-forms - angular-material - casting - jmeter - google-api - linked-list - path - timer - django-templates - arduino - proxy - orm - directory - windows-phone-7 - parse-platform - visual-studio-2015 - cron - conditional-statements - push-notification - functional-programming - primefaces - pagination - model - jar - xamarin.android - hyperlink - uiview - visual-studio-2013 - vbscript - google-cloud-functions - gitlab - azure-active-directory - jwt - download - swift3 - sql-server-2005 - configuration - process - rspec - pygame - properties - combobox - callback - windows-phone-8 - linux-kernel - safari - scrapy - permissions - emacs - scripting - raspberry-pi - clojure - x86 - scope - io - expo - azure-functions - compilation - responsive-design - mongodb-query - nhibernate - angularjs-directive - request - bluetooth - reference - binding - dns - architecture - 3d - playframework - pyqt - version-control - discord.js - doctrine-orm - package - f\# - rubygems - get - sql-server-2012 - autocomplete - tree - openssl - datepicker - kendo-ui - jackson - yii - controller - grep - nested - xamarin.ios - static - null - statistics - transactions - datagrid - active-directory - dockerfile - uiviewcontroller - webforms - discord.py - phpmyadmin - sas - computer-vision - notifications - duplicates - mocking - pycharm - youtube - yaml - nullpointerexception - menu - blazor - sum - plotly - bitmap - asp.net-mvc-5 - visual-studio-2008 - yii2 - electron - floating-point - css-selectors - stl - jsf-2 - android-listview - time-series - cryptography - ant - hashmap - character-encoding - stream - msbuild - asp.net-core-mvc - sdk - google-drive-api - jboss - selenium-chromedriver - joomla - devise - cors - navigation - anaconda - cuda - background - frontend - binary - multiprocessing - pyqt5 - camera - iterator - linq-to-sql - mariadb - onclick - android-jetpack-compose - ios7 - microsoft-graph-api - rabbitmq - android-asynctask - tabs - laravel-4 - environment-variables - amazon-dynamodb - insert - uicollectionview - linker - xsd - coldfusion - console - continuous-integration - upload - textview - ftp - opengl-es - macros - operating-system - mockito - localization - formatting - xml-parsing - vuejs3 - json.net - type-conversion - data.table - kivy - timestamp - integer - calendar - segmentation-fault - android-ndk - prolog - drag-and-drop - char - crash - jasmine - dependencies - automated-tests - geometry - azure-pipelines - android-gradle-plugin - itext - fortran - sprite-kit - header - mfc - firebase-cloud-messaging - attributes - nosql - format - nuxt.js - odoo - db2 - jquery-plugins - event-handling - jenkins-pipeline - nestjs - julia - leaflet - annotations - flutter-layout - keyboard - postman - textbox - arm - visual-studio-2017 - gulp - stripe-payments - libgdx - synchronization - timezone - uikit - azure-web-app-service - dom-events - xampp - wso2 - crystal-reports - swagger - namespaces - android-emulator - aggregation-framework - uiscrollview - jvm - google-sheets-formula - sequelize.js - com - chart.js - snowflake-cloud-data-platform - subprocess - geolocation - webdriver - html5-canvas - centos - garbage-collection - dialog - sql-update - widget - numbers - concatenation - qml - tuples - set - java-stream - smtp - mapreduce - ionic2 - windows-10 - rotation - android-edittext - modal-dialog - spring-data - nuget - doctrine - radio-button - http-headers - grid - sonarqube - lucene - xmlhttprequest - listbox - switch-statement - initialization - internationalization - components - apache-camel - boolean - google-play - serial-port - gdb - ios5 - ldap - return - youtube-api - eclipse-plugin - pivot - latex - frameworks - tags - containers - github-actions - c++17 - subquery - dataset - asp-classic - foreign-keys - label - embedded - uinavigationcontroller - copy - delegates - struts2 - google-cloud-storage - migration - protractor - base64 - queue - find - uibutton - sql-server-2008-r2 - arguments - composer-php - append - jaxb - zip - stack - tailwind-css - cucumber - autolayout - ide - entity-framework-6 - iteration - popup - r-markdown - windows-7 - airflow - vb6 - g++ - ssl-certificate - hover - clang - jqgrid - gmail - range Next You’ll be prompted to create an account to view your personalized homepage. 1. 1. [Home](https://stackoverflow.com/) 2. [Questions](https://stackoverflow.com/questions) 3. [AI Assist Labs](https://stackoverflow.ai/) 4. [Tags](https://stackoverflow.com/tags) 5. [Challenges](https://stackoverflow.com/beta/challenges) 6. [Chat](https://chat.stackoverflow.com/rooms/259507/stack-overflow-lobby) 7. [Articles](https://stackoverflow.blog/contributed?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=so-blog&utm_content=experiment-articles) 8. [Users](https://stackoverflow.com/users) 9. [Companies](https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&so_source=SiteNav) 10. [Collectives]() 11. Communities for your favorite technologies. [Explore all Collectives](https://stackoverflow.com/collectives-all) 2. Teams ![](https://cdn.sstatic.net/Img/teams/teams-promo.svg?v=e507948b81bf) Ask questions, find answers and collaborate at work with Stack Overflow for Teams. [Try Teams for free](https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) [Explore Teams](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) 3. [Teams]() 4. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. [Explore Teams](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact) ##### Collectives™ on Stack Overflow Find centralized, trusted content and collaborate around the technologies you use most. [Learn more about Collectives](https://stackoverflow.com/collectives) **Teams** Q\&A for work Connect and share knowledge within a single location that is structured and easy to search. [Learn more about Teams](https://stackoverflow.co/teams/) # ![Illustration of upvote icon after it is clicked](https://cdn.sstatic.net/Img/modal/img-upvote.png?v=fce73bd9724d) # Hang on, you can't upvote just yet. You'll need to complete a few actions and gain 15 reputation points before being able to upvote. **Upvoting** indicates when questions and answers are useful. [What's reputation and how do I get it?](https://stackoverflow.com/help/whats-reputation) Instead, you can save this post to reference later. Save this post for later Not now # ![Illustration of upvote icon after it is clicked](https://cdn.sstatic.net/Img/modal/img-free-votes.png?v=1c5aa3dac50b) # Thanks for your vote! You now have 5 free votes weekly. Free votes - count toward the total vote score - does not give reputation to the author Continue to help good content that is interesting, well-researched, and useful, rise to the top! To gain full voting privileges, [earn reputation](https://stackoverflow.com/help/whats-reputation). Got it\! Go to help center to learn more # [How do I print an exception in Python? \[duplicate\]](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python) [Ask Question](https://stackoverflow.com/questions/ask) Asked 16 years ago Modified [1 year, 5 months ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python?lastactivity "2024-04-27 19:25:22Z") Viewed 2.3m times This question shows research effort; it is useful and clear 1509 Save this question. Show activity on this post. **This question already has answers here**: [Catch and print full Python exception traceback without halting/exiting the program](https://stackoverflow.com/questions/3702675/catch-and-print-full-python-exception-traceback-without-halting-exiting-the-prog) (19 answers) Closed 5 months ago. How do I print the error/exception in the `except:` block? ``` try: ... except: print(exception) ``` - [python](https://stackoverflow.com/questions/tagged/python "show questions tagged 'python'") - [exception](https://stackoverflow.com/questions/tagged/exception "show questions tagged 'exception'") - [error-handling](https://stackoverflow.com/questions/tagged/error-handling "show questions tagged 'error-handling'") [Share](https://stackoverflow.com/q/1483429 "Short permalink to this question") Share a link to this question Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this question](https://stackoverflow.com/posts/1483429/edit) Follow Follow this question to receive notifications [edited Jun 20, 2022 at 6:52](https://stackoverflow.com/posts/1483429/revisions "show all edits to this post") [![Mateen Ulhaq's user avatar](https://i.sstatic.net/4cFxJ9Lj.jpg?s=64)](https://stackoverflow.com/users/365102/mateen-ulhaq) [Mateen Ulhaq](https://stackoverflow.com/users/365102/mateen-ulhaq) 27\.7k2121 gold badges120120 silver badges155155 bronze badges asked Sep 27, 2009 at 11:48 [![TIMEX's user avatar](https://www.gravatar.com/avatar/e77327f7ef0c6213525de4dcea19b200?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/179736/timex) [TIMEX](https://stackoverflow.com/users/179736/timex)TIMEX 274k369369 gold badges804804 silver badges1\.1k1\.1k bronze badges 2 - 7 Related: [How to print the full traceback without halting the program?](https://stackoverflow.com/q/3702675/3357935) Stevoisiak – [Stevoisiak](https://stackoverflow.com/users/3357935/stevoisiak "27,665 reputation") 2018-09-19 16:04:57 +00:00 [Commented Sep 19, 2018 at 16:04](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment91763704_1483429) - 3 Does this answer your question? [How to catch and print the full exception traceback without halting/exiting the program?](https://stackoverflow.com/questions/3702675/how-to-catch-and-print-the-full-exception-traceback-without-halting-exiting-the) Pythoneer – [Pythoneer](https://stackoverflow.com/users/20615590/pythoneer "423 reputation") 2023-01-07 11:49:37 +00:00 [Commented Jan 7, 2023 at 11:49](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment132422695_1483429) [Add a comment](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python "Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.") \| ## 11 Answers 11 Sorted by: [Reset to default](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python?answertab=scoredesc#tab-top) This answer is useful 2029 Save this answer. Show activity on this post. For Python 2.6 and later and Python 3.x: ``` except Exception as e: print(e) ``` For Python 2.5 and earlier, use: ``` except Exception,e: print str(e) ``` [Share](https://stackoverflow.com/a/1483488 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/1483488/edit) Follow Follow this answer to receive notifications [edited Aug 16, 2018 at 8:01](https://stackoverflow.com/posts/1483488/revisions "show all edits to this post") [![Jan's user avatar](https://www.gravatar.com/avatar/18da1a6c7300b2a41d940a13e61fb4be?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/2039571/jan) [Jan](https://stackoverflow.com/users/2039571/jan) 55677 silver badges1616 bronze badges answered Sep 27, 2009 at 12:19 [![jldupont's user avatar](https://www.gravatar.com/avatar/26eb5bb9dd2ccd72e2ccdc112ad1d050?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/171461/jldupont) [jldupont](https://stackoverflow.com/users/171461/jldupont)jldupont 97\.5k5858 gold badges211211 silver badges326326 bronze badges Sign up to request clarification or add additional context in comments. ## 8 Comments Add a comment [![](https://www.gravatar.com/avatar/43eaea281fd5ff0f5b459674e2308015?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1497199/dave) Dave [Dave](https://stackoverflow.com/users/1497199/dave) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment52430695_1483488) `str( KeyError('bad'))` =\> `'bad'` -- doesn't tell exception type 2015-08-28T16:47:39.99Z+00:00 136 Reply - Copy link [![](https://www.gravatar.com/avatar/6630bedc38c428fd65444f6ff6e26819?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/2421264/veggiet) Veggiet [Veggiet](https://stackoverflow.com/users/2421264/veggiet) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment96026224_1483488) print(e) on keyerrors seems to give only the key, but not the full exception message, which is less than helpful. 2019-02-10T13:03:30.08Z+00:00 58 Reply - Copy link [![](https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/100297/martijn-pieters) Martijn Pieters [Martijn Pieters](https://stackoverflow.com/users/100297/martijn-pieters) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment102901727_1483488) If you are going to print the exception, it is better to use `print(repr(e))`; the base `Exception.__str__` implementation only returns the exception message, not the type. Or, use the `traceback` module, which has methods for printing the current exception, formatted, or the full traceback. 2019-10-07T09:55:15.14Z+00:00 117 Reply - Copy link [![](https://i.sstatic.net/jtMofH1F.jpg?s=64)](https://stackoverflow.com/users/2388257/hi-angel) Hi-Angel [Hi-Angel](https://stackoverflow.com/users/2388257/hi-angel) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment115543926_1483488) @MartijnPieters the `print(repr(e))` doesn't give any stracktrace. The `print_exc` from traceback module *(mentioned in the other answer)* though works in this case. 2020-12-18T11:10:48.553Z+00:00 6 Reply - Copy link [![](https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/100297/martijn-pieters) Martijn Pieters [Martijn Pieters](https://stackoverflow.com/users/100297/martijn-pieters) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment115696697_1483488) @Hi-Angel: Where am I claiming that printing `repr(e)` would give the stack trace? I'm talking about the difference between `str(e)` and `repr(e)`, the latter includes more information that you would also see in the last line(s) of a traceback. I explicitly mention the `traceback` module in my comment. 2020-12-24T16:36:55.847Z+00:00 13 Reply - Copy link Add a comment \| Show 3 more comments This answer is useful 834 Save this answer. Show activity on this post. The [`traceback`](http://docs.python.org/library/traceback.html) module provides methods for [formatting and printing exceptions](https://docs.python.org/3/library/traceback.html#traceback-examples) and their tracebacks, e.g. this would print exception like the default handler does: ``` import traceback try: 1/0 except Exception: traceback.print_exc() ``` Output: ``` Traceback (most recent call last): File "C:\scripts\divide_by_zero.py", line 4, in <module> 1/0 ZeroDivisionError: division by zero ``` [Share](https://stackoverflow.com/a/1483494 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/1483494/edit) Follow Follow this answer to receive notifications [edited Sep 19, 2018 at 15:44](https://stackoverflow.com/posts/1483494/revisions "show all edits to this post") [![Stevoisiak's user avatar](https://i.sstatic.net/jaomO.png?s=64)](https://stackoverflow.com/users/3357935/stevoisiak) [Stevoisiak](https://stackoverflow.com/users/3357935/stevoisiak) 27\.7k3232 gold badges138138 silver badges245245 bronze badges answered Sep 27, 2009 at 12:25 [![Cat Plus Plus's user avatar](https://www.gravatar.com/avatar/0c4f4df702b23c8983f57d7113e809c8?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/16102/cat-plus-plus) [Cat Plus Plus](https://stackoverflow.com/users/16102/cat-plus-plus)Cat Plus Plus 131k2727 gold badges205205 silver badges226226 bronze badges ## 8 Comments Add a comment [![](https://lh6.googleusercontent.com/-l1bIhVhFa7g/AAAAAAAAAAI/AAAAAAAAAWE/oPd2eheD2Yw/s48-rj/photo.jpg)](https://stackoverflow.com/users/1893082/mikeschem) MikeSchem [MikeSchem](https://stackoverflow.com/users/1893082/mikeschem) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment86053380_1483494) is there some kind of get\_error\_message call that I can print with seeing as I'm using my own printing routine to add some other things. 2018-03-27T23:06:35.827Z+00:00 9 Reply - Copy link [![](https://www.gravatar.com/avatar/8e25278062e3d15a6c9bbd820f4cb2b1?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/8356505/heyzling) heyzling [heyzling](https://stackoverflow.com/users/8356505/heyzling) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment95994395_1483494) @MikeSchem `error_message = traceback.format_exc()` 2019-02-08T19:31:01.267Z+00:00 72 Reply - Copy link [![](https://graph.facebook.com/598481447/picture?type=large)](https://stackoverflow.com/users/4298208/aaronsteers) aaronsteers [aaronsteers](https://stackoverflow.com/users/4298208/aaronsteers) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment101587645_1483494) This snipped does not use the captured exception object. Can you expand the code to use 'ex'? - as in `except Exception as ex:`... 2019-08-19T19:42:08.727Z+00:00 5 Reply - Copy link [![](https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/100297/martijn-pieters) Martijn Pieters [Martijn Pieters](https://stackoverflow.com/users/100297/martijn-pieters) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment102901804_1483494) @aaronsteers it does use the captured exception; in an exception handler the current exception is available via the `sys.exc_info()` function and the `traceback.print_exc()` function gets it from there. You’d only ever need to pass in an exception explicitly when not handling an exception or when you want to show info based on a different exception. 2019-10-07T09:57:56.193Z+00:00 9 Reply - Copy link [![](https://graph.facebook.com/598481447/picture?type=large)](https://stackoverflow.com/users/4298208/aaronsteers) aaronsteers [aaronsteers](https://stackoverflow.com/users/4298208/aaronsteers) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment102979290_1483494) Yes, I would sometimes like to hold onto the exception and print it later, when I'm no longer in the 'except' block. 2019-10-09T16:55:52.443Z+00:00 7 Reply - Copy link Add a comment \| Show 3 more comments This answer is useful 202 Save this answer. Show activity on this post. In **Python 2.6 or greater** it's a bit cleaner: ``` except Exception as e: print(e) ``` In older versions it's still quite readable: ``` except Exception, e: print e ``` [Share](https://stackoverflow.com/a/1483909 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/1483909/edit) Follow Follow this answer to receive notifications [edited Jun 2, 2014 at 13:42](https://stackoverflow.com/posts/1483909/revisions "show all edits to this post") [![Max's user avatar](https://www.gravatar.com/avatar/873ad707fb34aac8fbdfbfec676e02e9?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/503402/max) [Max](https://stackoverflow.com/users/503402/max) 22\.5k77 gold badges5454 silver badges7979 bronze badges answered Sep 27, 2009 at 16:42 [![ilya n.'s user avatar](https://www.gravatar.com/avatar/2861bfeb71de9de58206bb6ae750bc2f?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/115200/ilya-n) [ilya n.](https://stackoverflow.com/users/115200/ilya-n)ilya n. 18\.9k1616 gold badges7575 silver badges9090 bronze badges ## 1 Comment Add a comment [![](https://i.sstatic.net/hrwqi.jpg?s=64)](https://stackoverflow.com/users/12740851/end-genocide-save-gaza) End genocide - save Gaza [End genocide - save Gaza](https://stackoverflow.com/users/12740851/end-genocide-save-gaza) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment137281561_1483909) This solution was exactly said above! (see previous ones then write) 2024-01-24T05:53:26.4Z+00:00 5 Reply - Copy link This answer is useful 144 Save this answer. Show activity on this post. # Python 3: `logging` Instead of using the basic `print()` function, the more flexible [`logging`](https://docs.python.org/3/library/logging.html) module can be used to log the exception. The `logging` module offers a lot extra functionality, for example, logging messages... - into a given log file, or - with timestamps and additional information about where the logging happened. For more information check out the official [documentation](https://docs.python.org/3/howto/logging.html). *** ## Usage Logging an exception can be done with the module-level function [`logging.exception()`](https://docs.python.org/3/library/logging.html#logging.exception) like so: ``` import logging try: 1/0 except BaseException: logging.exception("An exception was thrown!") ``` ### Output ``` ERROR:root:An exception was thrown! Traceback (most recent call last): File ".../Desktop/test.py", line 4, in <module> 1/0 ZeroDivisionError: division by zero ``` ### Notes - the function `logging.exception()` should only be called from an exception handler - the `logging` module should not be used inside a logging handler to avoid a `RecursionError` (thanks [@PrakharPandey](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment105920510_58622091)) *** ## Alternative log-levels It's also possible to log the exception with another [log level](https://docs.python.org/3/library/logging.html#logging-levels) but still show the exception details by using the keyword argument `exc_info=True`, like so: ``` logging.critical("An exception was thrown!", exc_info=True) logging.error ("An exception was thrown!", exc_info=True) logging.warning ("An exception was thrown!", exc_info=True) logging.info ("An exception was thrown!", exc_info=True) logging.debug ("An exception was thrown!", exc_info=True) # or the general form logging.log(level, "An exception was thrown!", exc_info=True) ``` *** ## Name and description only Of course, if you don't want the whole traceback but only some specific information (e.g., exception name and description), you can still use the `logging` module like so: ``` try: 1/0 except BaseException as exception: logging.warning(f"Exception Name: {type(exception).__name__}") logging.warning(f"Exception Desc: {exception}") ``` ### Output ``` WARNING:root:Exception Name: ZeroDivisionError WARNING:root:Exception Desc: division by zero ``` [Share](https://stackoverflow.com/a/58622091 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/58622091/edit) Follow Follow this answer to receive notifications [edited Apr 27, 2024 at 19:24](https://stackoverflow.com/posts/58622091/revisions "show all edits to this post") [![Benjamin Loison's user avatar](https://www.gravatar.com/avatar/cb0388d1c21590c716f03bed19bd36be?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/7123660/benjamin-loison) [Benjamin Loison](https://stackoverflow.com/users/7123660/benjamin-loison) 5,73144 gold badges1919 silver badges3737 bronze badges answered Oct 30, 2019 at 9:22 [![winklerrr's user avatar](https://www.gravatar.com/avatar/91422140f7a67322111a980c75b06826?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/3459910/winklerrr) [winklerrr](https://stackoverflow.com/users/3459910/winklerrr)winklerrr 15\.1k99 gold badges8383 silver badges9797 bronze badges ## 4 Comments Add a comment [![](https://lh5.googleusercontent.com/-ghpEZWEPDG8/AAAAAAAAAAI/AAAAAAAAAFs/8l4t4etxYqw/s48-rj/photo.jpg)](https://stackoverflow.com/users/6916314/prakhar-pandey) Prakhar Pandey [Prakhar Pandey](https://stackoverflow.com/users/6916314/prakhar-pandey) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment105920510_58622091) Should not be used inside a logging handler to avoid RecursionError 2020-01-24T12:32:05.153Z+00:00 8 Reply - Copy link [![](https://i.sstatic.net/LnQ8W.png?s=64)](https://stackoverflow.com/users/146555/sqqqrly) sqqqrly [sqqqrly](https://stackoverflow.com/users/146555/sqqqrly) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment133909486_58622091) In this example, the exception is logged and the exception is "handled". One may wish to re-raise this exception, if not sufficiently handled. 2023-04-03T14:01:14.613Z+00:00 1 Reply - Copy link [![](https://www.gravatar.com/avatar/89c6d1c69638b28ff787e07646d7cf00?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/3810316/convexity) Convexity [Convexity](https://stackoverflow.com/users/3810316/convexity) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment135668501_58622091) This "logging.exception()" is great! It has alwas worked well for me. When I, instead, logged "Exception" or anything in the other answers, sometimes it worked well, sometimes it printed another "error", sometimes it did not tell the filename and line number of the error, and sometimes it logged a wrong file and line number. 2023-08-23T07:06:28.46Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/1341de8fe6296871ae8395157ea4cde4?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/986896/kuchara) Kuchara [Kuchara](https://stackoverflow.com/users/986896/kuchara) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment137770073_58622091) Excepting `BaseException` may be risky. See note for KeyboardInterrupt at the official documentation: [docs.python.org/3/library/exceptions.html\#KeyboardInterrupt](https://docs.python.org/3/library/exceptions.html#KeyboardInterrupt) 2024-03-12T11:55:06.097Z+00:00 0 Reply - Copy link Add a comment This answer is useful 98 Save this answer. Show activity on this post. Expanding off of the "except Exception as e:" solution here is a nice one liner which includes some additional info like the type of error and where it occurred. ``` try: 1/0 except Exception as e: print(f"{type(e).__name__} at line {e.__traceback__.tb_lineno} of {__file__}: {e}") ``` Output: ``` ZeroDivisionError at line 48 of /Users/.../script.py: division by zero ``` [Share](https://stackoverflow.com/a/67112173 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/67112173/edit) Follow Follow this answer to receive notifications [edited Jan 11, 2024 at 12:29](https://stackoverflow.com/posts/67112173/revisions "show all edits to this post") [![Benjamin Loison's user avatar](https://www.gravatar.com/avatar/cb0388d1c21590c716f03bed19bd36be?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/7123660/benjamin-loison) [Benjamin Loison](https://stackoverflow.com/users/7123660/benjamin-loison) 5,73144 gold badges1919 silver badges3737 bronze badges answered Apr 15, 2021 at 16:15 [![Liam Roberts's user avatar](https://lh3.googleusercontent.com/-_zf6io2i0lQ/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3rcnBU7-vcgJhMHndrSXkp1sLTz5DA/s64-rj/photo.jpg)](https://stackoverflow.com/users/12196081/liam-roberts) [Liam Roberts](https://stackoverflow.com/users/12196081/liam-roberts)Liam Roberts 1,34199 silver badges77 bronze badges ## 8 Comments Add a comment [![](https://i.sstatic.net/Feexc.jpg?s=64)](https://stackoverflow.com/users/6072570/trishant-pahwa) Trishant Pahwa [Trishant Pahwa](https://stackoverflow.com/users/6072570/trishant-pahwa) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment129205767_67112173) The most useful answer. 2022-07-28T18:57:24.147Z+00:00 8 Reply - Copy link [![](https://www.gravatar.com/avatar/b870277843e2c2142457f50a834c600e?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/5437090/farid) farid [farid](https://stackoverflow.com/users/5437090/farid) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment132519000_67112173) for me `pint(e)` only returns `Message:` nothing else in python 3.7 anaconda 2023-01-12T10:07:41.177Z+00:00 1 Reply - Copy link [![](https://i.sstatic.net/Bx6V4.jpg?s=64)](https://stackoverflow.com/users/3304490/izzulmakin) izzulmakin [izzulmakin](https://stackoverflow.com/users/3304490/izzulmakin) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment135130752_67112173) had to scroll down too far to get the real answer. 2023-07-08T23:16:27.91Z+00:00 1 Reply - Copy link [![](https://www.gravatar.com/avatar/ae917fb5558a151d5689fb1a50abc932?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/998984/jayzee) JayZee [JayZee](https://stackoverflow.com/users/998984/jayzee) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment136964340_67112173) It is maybe useful for the sake of example to know where to grab the information of the exception, but it is really clumsy if you think to handle all exceptions this way. 2023-12-20T06:04:17.25Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/65552407e8d2abe055b1b8fb87f2a510?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1493426/hbrent) hBrent [hBrent](https://stackoverflow.com/users/1493426/hbrent) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment137598048_67112173) @JayZee, not clumsy if you write a function consisting of the print line in the answer and just pass the exception to that function from every exception block. 2024-02-23T22:21:40.217Z+00:00 0 Reply - Copy link Add a comment \| Show 3 more comments This answer is useful 89 Save this answer. Show activity on this post. (I was going to leave this as a comment on [@jldupont's answer](https://stackoverflow.com/a/1483488), but I don't have enough reputation.) I've seen answers like @jldupont's answer in other places as well. FWIW, I think it's important to note that this: ``` except Exception as e: print(e) ``` will print the error output to `sys.stdout` by default. A more appropriate approach to error handling in general would be: ``` except Exception as e: print(e, file=sys.stderr) ``` (Note that you have to `import sys` for this to work.) This way, the error is printed to `STDERR` instead of `STDOUT`, which allows for the proper output parsing/redirection/etc. I understand that the question was strictly about 'printing an error', but it seems important to point out the best practice here rather than leave out this detail that could lead to non-standard code for anyone who doesn't eventually learn better. I haven't used the `traceback` module as in [Cat Plus Plus's answer](https://stackoverflow.com/a/1483494), and maybe that's the best way, but I thought I'd throw this out there. [Share](https://stackoverflow.com/a/52450152 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/52450152/edit) Follow Follow this answer to receive notifications [edited Apr 27, 2024 at 19:25](https://stackoverflow.com/posts/52450152/revisions "show all edits to this post") [![Benjamin Loison's user avatar](https://www.gravatar.com/avatar/cb0388d1c21590c716f03bed19bd36be?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/7123660/benjamin-loison) [Benjamin Loison](https://stackoverflow.com/users/7123660/benjamin-loison) 5,73144 gold badges1919 silver badges3737 bronze badges answered Sep 21, 2018 at 19:38 [![grish's user avatar](https://i.sstatic.net/eQmWm.jpg?s=64)](https://stackoverflow.com/users/4516052/grish) [grish](https://stackoverflow.com/users/4516052/grish)grish 1,15111 gold badge88 silver badges99 bronze badges ## 2 Comments Add a comment [![](https://i.sstatic.net/o7oaO.png?s=64)](https://stackoverflow.com/users/1002016/cameron-kerr) Cameron Kerr [Cameron Kerr](https://stackoverflow.com/users/1002016/cameron-kerr) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment96037887_52450152) I would suggest further adding flush=True. I've noticed with systemd (and not using a proper logging framework), that buffering when capturing to the journal is not what I would have expected. 2019-02-11T00:42:32.087Z+00:00 4 Reply - Copy link [![](https://lh3.googleusercontent.com/a-/AOh14GgmJJDSb3ma8Be2l6_sdsTBzvKTEEr_N1egfWPqDw=k-s48)](https://stackoverflow.com/users/14830457/avighnac) avighnac [avighnac](https://stackoverflow.com/users/14830457/avighnac) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment133707197_52450152) @CameronKerr isn’t ‘stderr’ not buffered? 2023-03-21T07:19:06.91Z+00:00 0 Reply - Copy link This answer is useful 73 Save this answer. Show activity on this post. In case you want to pass error strings, here is an example from [Errors and Exceptions](http://docs.python.org/tutorial/errors.html) (Python 2.6) ``` >>> try: ... raise Exception('spam', 'eggs') ... except Exception as inst: ... print type(inst) # the exception instance ... print inst.args # arguments stored in .args ... print inst # __str__ allows args to printed directly ... x, y = inst # __getitem__ allows args to be unpacked directly ... print 'x =', x ... print 'y =', y ... <type 'exceptions.Exception'> ('spam', 'eggs') ('spam', 'eggs') x = spam y = eggs ``` [Share](https://stackoverflow.com/a/1483447 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://stackoverflow.com/posts/1483447/edit) Follow Follow this answer to receive notifications [edited Sep 27, 2009 at 12:26](https://stackoverflow.com/posts/1483447/revisions "show all edits to this post") answered Sep 27, 2009 at 11:56 [![Nick Dandoulakis's user avatar](https://www.gravatar.com/avatar/17a81b603f4a5f6d4eaa55b9fd6c06c5?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/108130/nick-dandoulakis) [Nick Dandoulakis](https://stackoverflow.com/users/108130/nick-dandoulakis)Nick Dandoulakis 43\.3k1717 gold badges106106 silver badges139139 bronze badges ## Comments Add a comment This answer is useful 73 Save this answer. Show activity on this post. One has pretty much control on which information from the traceback to be displayed/logged when catching exceptions. The code ``` with open("not_existing_file.txt", 'r') as text: pass ``` would produce the following traceback: ``` Traceback (most recent call last): File "exception_checks.py", line 19, in <module> with open("not_existing_file.txt", 'r') as text: FileNotFoundError: [Errno 2] No such file or directory: 'not_existing_file.txt' ``` ## Print/Log the full traceback As others already mentioned, you can catch the whole traceback by using the traceback module: ``` import traceback try: with open("not_existing_file.txt", 'r') as text: pass except Exception as exception: traceback.print_exc() ``` This will produce the following output: ``` Traceback (most recent call last): File "exception_checks.py", line 19, in <module> with open("not_existing_file.txt", 'r') as text: FileNotFoundError: [Errno 2] No such file or directory: 'not_existing_file.txt' ``` You can achieve the same by using logging: ``` try: with open("not_existing_file.txt", 'r') as text: pass except Exception as exception: logger.error(exception, exc_info=True) ``` Output: ``` __main__: 2020-05-27 12:10:47-ERROR- [Errno 2] No such file or directory: 'not_existing_file.txt' Traceback (most recent call last): File "exception_checks.py", line 27, in <module> with open("not_existing_file.txt", 'r') as text: FileNotFoundError: [Errno 2] No such file or directory: 'not_existing_file.txt' ``` ## Print/log error name/message only You might not be interested in the whole traceback, but only in the most important information, such as Exception name and Exception message, use: ``` try: with open("not_existing_file.txt", 'r') as text: pass except Exception as exception: print("Exception: {}".format(type(exception).__name__)) print("Exception message: {}".format(exception)) ``` Output: ``` Exception: FileNotFoundError Exception message: [Errno 2] No such file or directory: 'not_existing_file.txt' ``` [Share](https://stackoverflow.com/a/61226203 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/61226203/edit) Follow Follow this answer to receive notifications [edited May 27, 2020 at 10:22](https://stackoverflow.com/posts/61226203/revisions "show all edits to this post") answered Apr 15, 2020 at 10:10 [![GinTonic's user avatar](https://www.gravatar.com/avatar/b5e63d092240494dd13bc5a929384ca2?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/13012584/gintonic) [GinTonic](https://stackoverflow.com/users/13012584/gintonic)GinTonic 1,03088 silver badges1111 bronze badges ## 3 Comments Add a comment [![](https://www.gravatar.com/avatar/ced7f76fd1b5573ce3bdce2f3392df04?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/423105/larsh) LarsH [LarsH](https://stackoverflow.com/users/423105/larsh) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment112008561_61226203) Wish I could upvote this answer many times, as it's significantly more helpful than the accepted one. 2020-08-10T16:01:19.733Z+00:00 8 Reply - Copy link [![](https://i.sstatic.net/qs2RW.png?s=64)](https://stackoverflow.com/users/14146687/pigeonburger) pigeonburger [pigeonburger](https://stackoverflow.com/users/14146687/pigeonburger) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment112829904_61226203) With the last section in your answer ('Print/log error name\\message only') how can I print both `Exception` and `Exception Message` using `print` only once? Whenever I try to do it, it turns out all weird. 2020-09-09T06:58:22.923Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/fb85d6c2bacd710c170e4bc6ae18842c?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/15611749/theprocoder) theProCoder [theProCoder](https://stackoverflow.com/users/15611749/theprocoder) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment123159792_61226203) `print(f"Exception: {type(exception).__name__}\nException message: {exception}")`. The `f` at the beginning signifies that it is an `f-string`, which just allows you to put the expression in the curly braces instead of using `.format()`. `f-strings` only work on systems running Python 3.6+ however 2021-10-22T12:49:03.64Z+00:00 1 Reply - Copy link Add a comment This answer is useful 40 Save this answer. Show activity on this post. Try this ``` try: print("Hare Krishna!") except Exception as er: print(er) ``` [Share](https://stackoverflow.com/a/71192395 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/71192395/edit) Follow Follow this answer to receive notifications [edited Feb 10, 2023 at 10:15](https://stackoverflow.com/posts/71192395/revisions "show all edits to this post") [![vvvvv's user avatar](https://i.sstatic.net/fzsuf.jpg?s=64)](https://stackoverflow.com/users/5446749/vvvvv) [vvvvv](https://stackoverflow.com/users/5446749/vvvvv) 32\.8k1919 gold badges6969 silver badges103103 bronze badges answered Feb 20, 2022 at 7:57 [![Raj Maddheshiya's user avatar](https://graph.facebook.com/776403396430264/picture?type=large)](https://stackoverflow.com/users/14094055/raj-maddheshiya) [Raj Maddheshiya](https://stackoverflow.com/users/14094055/raj-maddheshiya)Raj Maddheshiya 57844 silver badges77 bronze badges ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/f5d2ac40c87c1199cfc5442970ec2ae6?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/3986395/simas-joneliunas) Simas Joneliunas [Simas Joneliunas](https://stackoverflow.com/users/3986395/simas-joneliunas) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment125936363_71192395) Usually a code block with no explanation is not a very good answer. It helps the community much more if you could tell us why we should try this code and why it would/might help the op. Thanks\! 2022-02-24T02:27:32.693Z+00:00 14 Reply - Copy link This answer is useful 6 Save this answer. Show activity on this post. I would recommend using a try-except statement. Also, rather than using a print statement, a logging exception logs a message with level ERROR on the logger, which I find is more effective than a print output. This method should only be called from an exception handler, as it is here: ``` import logging try: *code goes here* except BaseException: logging.exception("*Error goes here*") ``` There's good documentation on [this python page](https://docs.python.org/3/library/logging.html) if you want to learn more about logging and debugging. [Share](https://stackoverflow.com/a/68577523 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/68577523/edit) Follow Follow this answer to receive notifications answered Jul 29, 2021 at 14:11 [![alio's user avatar](https://www.gravatar.com/avatar/73e73eab5fc21dbf1f3f3a5c4075eaa7?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/15482106/alio) [alio](https://stackoverflow.com/users/15482106/alio)alio 18411 silver badge66 bronze badges ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/22c2f9ee23745107e291cf116e4e35ba?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/9063378/melendowski) Melendowski [Melendowski](https://stackoverflow.com/users/9063378/melendowski) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment130903067_68577523) Its difficult to judge in the repl, am I correct in thinking that this prints the exception but does not halt the program? I.e. I can still gracefully exit. 2022-10-20T14:48:48.263Z+00:00 0 Reply - Copy link This answer is useful 4 Save this answer. Show activity on this post. One liner error raising can be done with assert statements if that's what you want to do. This will help you write statically fixable code and check errors early. ``` assert type(A) is type(""), "requires a string" ``` [Share](https://stackoverflow.com/a/1483798 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/1483798/edit) Follow Follow this answer to receive notifications [edited Jun 1, 2018 at 15:15](https://stackoverflow.com/posts/1483798/revisions "show all edits to this post") [![Stevoisiak's user avatar](https://i.sstatic.net/jaomO.png?s=64)](https://stackoverflow.com/users/3357935/stevoisiak) [Stevoisiak](https://stackoverflow.com/users/3357935/stevoisiak) 27\.7k3232 gold badges138138 silver badges245245 bronze badges answered Sep 27, 2009 at 15:38 [![whatnick's user avatar](https://www.gravatar.com/avatar/aaa598c2215dc597db2206fa553a7766?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/176958/whatnick) [whatnick](https://stackoverflow.com/users/176958/whatnick)whatnick 5,50033 gold badges2222 silver badges3636 bronze badges ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/1b4e747120238b5fabd032ce55c327c5?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/835945/alois-mahdal) Alois Mahdal [Alois Mahdal](https://stackoverflow.com/users/835945/alois-mahdal) [Over a year ago](https://stackoverflow.com/questions/1483429/how-do-i-print-an-exception-in-python#comment128585055_1483798) `assert` statements should not be used for normal logic; they are ignored if python runs with `-O`. See python(1). 2022-06-29T09:55:51.35Z+00:00 0 Reply - Copy link **[Protected question](https://stackoverflow.com/help/privileges/protect-questions)**. To answer this question, you need to have at least 10 reputation on this site (not counting the [association bonus](https://meta.stackexchange.com/questions/141648/what-is-the-association-bonus-and-how-does-it-work)). The reputation requirement helps protect this question from spam and non-answer activity. Start asking to get answers Find the answer to your question by asking. [Ask question](https://stackoverflow.com/questions/ask) Explore related questions - [python](https://stackoverflow.com/questions/tagged/python "show questions tagged 'python'") - [exception](https://stackoverflow.com/questions/tagged/exception "show questions tagged 'exception'") - [error-handling](https://stackoverflow.com/questions/tagged/error-handling "show questions tagged 'error-handling'") See similar questions with these tags. - The Overflow Blog - [Making your code base better will make your code coverage worse](https://stackoverflow.blog/2025/09/29/making-your-code-base-better-will-make-your-code-coverage-worse/?cb=1) - [As your AI gets smarter, so must your API](https://stackoverflow.blog/2025/09/30/as-your-ai-gets-smarter-so-must-your-api/?cb=1) - Featured on Meta - [Spevacus has joined us as a Community Manager](https://meta.stackexchange.com/questions/412667/spevacus-has-joined-us-as-a-community-manager?cb=1) - [Introducing a new proactive anti-spam measure](https://meta.stackexchange.com/questions/412705/introducing-a-new-proactive-anti-spam-measure?cb=1) - [Policy: Generative AI (e.g., ChatGPT) is banned](https://meta.stackoverflow.com/questions/421831/policy-generative-ai-e-g-chatgpt-is-banned?cb=1) - [New comment UI experiment graduation](https://meta.stackoverflow.com/questions/434861/new-comment-ui-experiment-graduation?cb=1) - [Exploring new types of questions on Stack Overflow](https://meta.stackoverflow.com/questions/435121/exploring-new-types-of-questions-on-stack-overflow?cb=1) Community activity Last 1 hr - Users online activity 19517 users online - 28 questions - 21 answers - 116 comments - 343 upvotes Popular tags [python](https://stackoverflow.com/questions/tagged/python)[c++](https://stackoverflow.com/questions/tagged/c++)[c\#](https://stackoverflow.com/questions/tagged/c)[postgresql](https://stackoverflow.com/questions/tagged/postgresql)[javascript](https://stackoverflow.com/questions/tagged/javascript)[java](https://stackoverflow.com/questions/tagged/java) Popular unanswered question [Can I alias a symbol in Common Lisp?](https://stackoverflow.com/questions/79780598) [common-lisp](https://stackoverflow.com/questions/tagged/common-lisp) [![User avatar](https://www.gravatar.com/avatar/25cd06518221e8ce6f3a4c8a5ccd711a?s=256&d=identicon&r=PG)](https://stackoverflow.com/users/125415) [Dan Passaro](https://stackoverflow.com/users/125415) - 4\.4k yesterday #### Linked [1599](https://stackoverflow.com/questions/3702675/catch-and-print-full-python-exception-traceback-without-halting-exiting-the-prog?lq=1 "Question score (upvotes - downvotes)") [Catch and print full Python exception traceback without halting/exiting the program](https://stackoverflow.com/questions/3702675/catch-and-print-full-python-exception-traceback-without-halting-exiting-the-prog?noredirect=1&lq=1) [8](https://stackoverflow.com/questions/62220197/how-to-catch-an-exception-message-in-python?lq=1 "Question score (upvotes - downvotes)") [How to catch an exception message in python?](https://stackoverflow.com/questions/62220197/how-to-catch-an-exception-message-in-python?noredirect=1&lq=1) [\-1](https://stackoverflow.com/questions/56042566/how-to-print-exception-while-specifying-error-type?lq=1 "Question score (upvotes - downvotes)") [How to print exception while specifying error type?](https://stackoverflow.com/questions/56042566/how-to-print-exception-while-specifying-error-type?noredirect=1&lq=1) [\-1](https://stackoverflow.com/questions/62763347/how-to-covert-an-exception-to-a-string-in-python?lq=1 "Question score (upvotes - downvotes)") [how to covert an exception to a string in python](https://stackoverflow.com/questions/62763347/how-to-covert-an-exception-to-a-string-in-python?noredirect=1&lq=1) [0](https://stackoverflow.com/questions/72183882/bypassing-and-printing-out-the-name-of-an-error-in-a-loop-python?lq=1 "Question score (upvotes - downvotes)") [Bypassing and printing out the name of an Error in a Loop - Python](https://stackoverflow.com/questions/72183882/bypassing-and-printing-out-the-name-of-an-error-in-a-loop-python?noredirect=1&lq=1) [1](https://stackoverflow.com/questions/63430466/is-it-possible-to-continue-execution-after-error-in-jupyter?lq=1 "Question score (upvotes - downvotes)") [Is it possible to continue execution after error in Jupyter?](https://stackoverflow.com/questions/63430466/is-it-possible-to-continue-execution-after-error-in-jupyter?noredirect=1&lq=1) [384](https://stackoverflow.com/questions/9823936/how-do-i-determine-what-type-of-exception-occurred?lq=1 "Question score (upvotes - downvotes)") [How do I determine what type of exception occurred?](https://stackoverflow.com/questions/9823936/how-do-i-determine-what-type-of-exception-occurred?noredirect=1&lq=1) [71](https://stackoverflow.com/questions/41596810/how-to-print-an-exception-in-python-3?lq=1 "Question score (upvotes - downvotes)") [How to print an exception in Python 3?](https://stackoverflow.com/questions/41596810/how-to-print-an-exception-in-python-3?noredirect=1&lq=1) [3](https://stackoverflow.com/questions/45131565/how-to-print-an-exception?lq=1 "Question score (upvotes - downvotes)") [How to print an exception?](https://stackoverflow.com/questions/45131565/how-to-print-an-exception?noredirect=1&lq=1) [3](https://stackoverflow.com/questions/29791833/print-error-type-error-statement-and-own-statement?lq=1 "Question score (upvotes - downvotes)") [Print error type, error statement and own statement](https://stackoverflow.com/questions/29791833/print-error-type-error-statement-and-own-statement?noredirect=1&lq=1) [See more linked questions](https://stackoverflow.com/questions/linked/1483429?lq=1) #### Related [9](https://stackoverflow.com/questions/3330991/what-is-the-proper-method-of-printing-python-exceptions?rq=3 "Question score (upvotes - downvotes)") [What is the proper method of printing Python Exceptions?](https://stackoverflow.com/questions/3330991/what-is-the-proper-method-of-printing-python-exceptions?rq=3) [3](https://stackoverflow.com/questions/13129453/printing-the-full-exception?rq=3 "Question score (upvotes - downvotes)") [Printing the full exception](https://stackoverflow.com/questions/13129453/printing-the-full-exception?rq=3) [3](https://stackoverflow.com/questions/13364023/printing-exceptions-in-python-instead-of-raising-them?rq=3 "Question score (upvotes - downvotes)") [Printing exceptions in Python, instead of raising them](https://stackoverflow.com/questions/13364023/printing-exceptions-in-python-instead-of-raising-them?rq=3) [0](https://stackoverflow.com/questions/14625405/exception-in-python?rq=3 "Question score (upvotes - downvotes)") [Exception in python](https://stackoverflow.com/questions/14625405/exception-in-python?rq=3) [4](https://stackoverflow.com/questions/16257422/printing-an-exception?rq=3 "Question score (upvotes - downvotes)") [Printing an exception](https://stackoverflow.com/questions/16257422/printing-an-exception?rq=3) [210](https://stackoverflow.com/questions/33239308/how-to-get-exception-message-in-python-properly?rq=3 "Question score (upvotes - downvotes)") [How to get exception message in Python properly](https://stackoverflow.com/questions/33239308/how-to-get-exception-message-in-python-properly?rq=3) [0](https://stackoverflow.com/questions/43942482/while-handling-exceptions-how-to-print-any-error-statement-that-occurs-see-bel?rq=3 "Question score (upvotes - downvotes)") [While handling Exceptions, how to print any error statement that occurs? See below for more details](https://stackoverflow.com/questions/43942482/while-handling-exceptions-how-to-print-any-error-statement-that-occurs-see-bel?rq=3) [3](https://stackoverflow.com/questions/45131565/how-to-print-an-exception?rq=3 "Question score (upvotes - downvotes)") [How to print an exception?](https://stackoverflow.com/questions/45131565/how-to-print-an-exception?rq=3) [0](https://stackoverflow.com/questions/55462665/how-do-i-print-an-exception-if-error-in-code?rq=3 "Question score (upvotes - downvotes)") [How do I print an exception if error in code?](https://stackoverflow.com/questions/55462665/how-do-i-print-an-exception-if-error-in-code?rq=3) [0](https://stackoverflow.com/questions/59924513/how-do-i-use-a-try-and-exception-to-raise-an-error-with-a-print-message-in-pytho?rq=3 "Question score (upvotes - downvotes)") [How do I use a Try and Exception to raise an error with a print message in Python?](https://stackoverflow.com/questions/59924513/how-do-i-use-a-try-and-exception-to-raise-an-error-with-a-print-message-in-pytho?rq=3) #### [Hot Network Questions](https://stackexchange.com/questions?tab=hot) - [Generic term for open-drain / open-collector](https://electronics.stackexchange.com/questions/756288/generic-term-for-open-drain-open-collector) - [How Do Quartiles Help Us Understand a Dataset?](https://stats.stackexchange.com/questions/670541/how-do-quartiles-help-us-understand-a-dataset) - [Can I replace a dead link source with a new publication during proofing?](https://academia.stackexchange.com/questions/221557/can-i-replace-a-dead-link-source-with-a-new-publication-during-proofing) - [Choosing options with invalid targets](https://boardgames.stackexchange.com/questions/63203/choosing-options-with-invalid-targets) - [Why does a mismatching printf specifier also affect subsequent arguments?](https://stackoverflow.com/questions/79779696/why-does-a-mismatching-printf-specifier-also-affect-subsequent-arguments) - [How to set up remote access on Kubuntu to a chromebook?](https://askubuntu.com/questions/1556865/how-to-set-up-remote-access-on-kubuntu-to-a-chromebook) - [How can I find other cyclists around me](https://bicycles.stackexchange.com/questions/97552/how-can-i-find-other-cyclists-around-me) - [Concerns about using ChatGPT with mathematical paper writing assistance](https://academia.stackexchange.com/questions/221542/concerns-about-using-chatgpt-with-mathematical-paper-writing-assistance) - [Comma splicing in screenplays](https://writing.stackexchange.com/questions/71888/comma-splicing-in-screenplays) - [Was Jaime Lannister actually 40 years old when Joffrey mocked him in Game of Thrones S04E01?](https://movies.stackexchange.com/questions/128526/was-jaime-lannister-actually-40-years-old-when-joffrey-mocked-him-in-game-of-thr) - [Adding multiple texts to different locations in Graphics3D](https://mathematica.stackexchange.com/questions/315579/adding-multiple-texts-to-different-locations-in-graphics3d) - [Amplifying signal post low pass filter](https://electronics.stackexchange.com/questions/756299/amplifying-signal-post-low-pass-filter) - [How can the Taiwanese government make business decisions for companies?](https://politics.stackexchange.com/questions/93662/how-can-the-taiwanese-government-make-business-decisions-for-companies) - [Why is my focaccia undercooked when using an air fryer?](https://cooking.stackexchange.com/questions/133179/why-is-my-focaccia-undercooked-when-using-an-air-fryer) - [Apply a function onto sublist and include an additional argument](https://mathematica.stackexchange.com/questions/315559/apply-a-function-onto-sublist-and-include-an-additional-argument) - [What type of adhesives can be used for stabilizing connections in electronics?](https://electronics.stackexchange.com/questions/756328/what-type-of-adhesives-can-be-used-for-stabilizing-connections-in-electronics) - [What are Philosophical arguments that justify that infinite rebirths before current birth is possible and not a contradiction?](https://philosophy.stackexchange.com/questions/130887/what-are-philosophical-arguments-that-justify-that-infinite-rebirths-before-curr) - [Why were only two nominees short- listed for Apostleship in Acts 1?](https://hermeneutics.stackexchange.com/questions/108608/why-were-only-two-nominees-short-listed-for-apostleship-in-acts-1) - [What is the actual role of the "watchers" in "The Final Days" by David Langford?](https://scifi.stackexchange.com/questions/299442/what-is-the-actual-role-of-the-watchers-in-the-final-days-by-david-langford) - [C++ lock free single linked list dedicated to word frequency](https://codereview.stackexchange.com/questions/298257/c-lock-free-single-linked-list-dedicated-to-word-frequency) - [Extension of positive operators counter-example](https://mathoverflow.net/questions/501104/extension-of-positive-operators-counter-example) - [Is Zorn's Lemma equivalent to the Axiom of Choice for individual sets?](https://mathoverflow.net/questions/501113/is-zorns-lemma-equivalent-to-the-axiom-of-choice-for-individual-sets) - [In a 3-phase transformer, why don't the windings induce voltages on the other phases?](https://electronics.stackexchange.com/questions/756389/in-a-3-phase-transformer-why-dont-the-windings-induce-voltages-on-the-other-ph) - [How epsilon and delta are related, and how the relation proves a limit.](https://math.stackexchange.com/questions/5099130/how-epsilon-and-delta-are-related-and-how-the-relation-proves-a-limit) ![](https://stackoverflow.com/posts/1483429/ivc/5d4c?prg=7fb4113c-ecc6-467c-b3a0-bfc017fb8715) lang-py # Why are you flagging this comment? Probable spam. This comment promotes a product, service or website while [failing to disclose the author's affiliation](https://stackoverflow.com/help/promotion). Unfriendly or contains harassment/bigotry/abuse. This comment is unkind, insulting or attacks another person or group. Learn more in our [Code of Conduct](https://stackoverflow.com/conduct/abusive-behavior). Not needed. This comment is not relevant to the post. ``` ``` Enter at least 6 characters Something else. A problem not listed above. Try to be as specific as possible. ``` ``` Enter at least 6 characters Flag comment Cancel You have 0 flags left today ##### [Stack Overflow](https://stackoverflow.com/) - [Questions](https://stackoverflow.com/questions) - [Help](https://stackoverflow.com/help) - [Chat](https://chat.stackoverflow.com/?tab=explore) ##### [Products](https://stackoverflow.co/) - [Teams](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=teams) - [Advertising](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=advertising) - [Talent](https://stackoverflow.co/advertising/employer-branding/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=talent) ##### [Company](https://stackoverflow.co/) - [About](https://stackoverflow.co/) - [Press](https://stackoverflow.co/company/press/) - [Work Here](https://stackoverflow.co/company/work-here/) - [Legal](https://stackoverflow.com/legal) - [Privacy Policy](https://stackoverflow.com/legal/privacy-policy) - [Terms of Service](https://stackoverflow.com/legal/terms-of-service/public) - [Contact Us](https://stackoverflow.com/contact) - Cookie Settings - [Cookie Policy](https://policies.stackoverflow.co/stack-overflow/cookie-policy) ##### [Stack Exchange Network](https://stackexchange.com/) - [Technology](https://stackexchange.com/sites#technology) - [Culture & recreation](https://stackexchange.com/sites#culturerecreation) - [Life & arts](https://stackexchange.com/sites#lifearts) - [Science](https://stackexchange.com/sites#science) - [Professional](https://stackexchange.com/sites#professional) - [Business](https://stackexchange.com/sites#business) - [API](https://api.stackexchange.com/) - [Data](https://data.stackexchange.com/) - [Blog](https://stackoverflow.blog/?blb=1) - [Facebook](https://www.facebook.com/officialstackoverflow/) - [Twitter](https://twitter.com/stackoverflow) - [LinkedIn](https://linkedin.com/company/stack-overflow) - [Instagram](https://www.instagram.com/thestackoverflow) Site design / logo © 2025 Stack Exchange Inc; user contributions licensed under [CC BY-SA](https://stackoverflow.com/help/licensing) . rev 2025.10.2.34811
Readable Markdownnull
Shard169 (laksa)
Root Hash714406497480128969
Unparsed URLcom,stackoverflow!/questions/1483429/how-do-i-print-an-exception-in-python s443