Skip to content
Fix Code Error

How to print an exception in Python?

March 13, 2021 by Code Error
Posted By: Anonymous
try:
    something here
except:
    print('the whatever error occurred.')

How can I print the error/exception in my except: block?

Solution

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)
Answered By: Anonymous

Related Articles

  • Validate that a string is a positive integer
  • problem with client server unix domain stream sockets…
  • How to avoid a System.Runtime.InteropServices.COMException?
  • How to check if a string contains text from an array of…
  • Can't understand the difference between declaring a pointer…
  • Reversing a string in C
  • How does String substring work in Swift
  • How to use Rust nom to write a parser for this kind of…
  • useEffect Error: Minified React error #321 (GTM…
  • Fix top buttons on scroll of list below

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

Next Post:

Where does PHP store the error log? (php5, apache, fastcgi, cpanel)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error