python except error message code example
Example 1: python get exception message
try:
with open(filepath,'rb') as f:
con.storbinary('STOR '+ filepath, f)
logger.info('File successfully uploaded to '+ FTPADDR)
except Exception as e:
logger.error('Failed to upload to ftp: '+ str(e))
Example 2: python try catch
try:
except ValueError:
except (BadThingError, HorrbileThingError) as e:
except:
else:
finally:
Example 3: error handling in python
try:
print(x)
except SyntaxError:
print("There is a SyntaxError in your code")
except NameError:
print("There is a NameError in your code")
except TypeError:
print("There is a TypeError in your code")