Answered by : afshin
try: # some code
except Exception as e: print("ERROR : "+str(e))
Source : | Last Update : Thu, 26 Nov 20
Answered by : frightened-fox-fkxu5urixg7a
try: with open(filepath,'rb') as f: con.storbinary('STOR '+ filepath, f) logger.info('File successfully uploaded to '+ FTPADDR)
except Exception as e: # work on python 3.x logger.error('Failed to upload to ftp: '+ str(e))
Source : https://stackoverflow.com/questions/4690600/python-exception-message-capturing | Last Update : Fri, 21 Aug 20
Answered by : terrible-tapir
except Exception as e: print(e)
Source : https://stackoverflow.com/questions/1483429/how-to-print-an-exception-in-python | Last Update : Fri, 27 Mar 20
Answered by : jawwson
# Raise is used to cause an error
raise(Exception("Put whatever you want here!"))
raise(TypeError)
Source : | Last Update : Sun, 19 Apr 20
Answered by : cheerful-caracal-07r34joh23k0
import sys
try: S = 1/0 #Create Error
except: # catch *all* exceptions e = sys.exc_info() print(e) # (Exception Type, Exception Value, TraceBack)
############
# OR #
############
try: S = 1/0
except ZeroDivisionError as e: print(e) # ZeroDivisionError('division by zero')
Source : | Last Update : Thu, 18 Jun 20
Answered by : relieved-rhinoceros-vfu41lbxpypi
try: print("I will try to print this line of code")
except: print("I will print this line of code if an error is encountered")
Source : | Last Update : Sun, 18 Oct 20
Answered by : jerred
except: pass
Source : | Last Update : Thu, 27 Aug 20
Answered by : you
try: # Code that may raise an exception a = 10 / 0
except Exception as e: exception_message = str(e) print(exception_message)
Source : | Last Update : Mon, 18 Sep 23
Answered by : santhosh-kumar-dhanasekaran
try: # do something pass
except: # this will print the message "An exception occurred and the traceback" # you can't have to explicitly give the message logger.exception("An exception occurred")
Source : | Last Update : Thu, 18 Nov 21
Answered by : grotesque-guanaco-2etwtmhaul1u
str(your_exception)
Source : | Last Update : Mon, 30 May 22