Answers for "custom errors python"

2

python custom errors

class MyException(Exception):
  """You can put code here"""
  pass

class MyOtherException(MyException):
  """You can also put code here"""
  pass
Posted by: Guest on June-29-2021
9

except as Exception:

>>> def catch():
...     try:
...         asd()
...     except Exception as e:
...         print e.message, e.args
... 
>>> catch()
global name 'asd' is not defined ("global name 'asd' is not defined",)
Posted by: Guest on April-28-2020
1

python custom errors

>>> class CustomError(Exception):
...     pass
...

>>> raise CustomError
Traceback (most recent call last):
...
__main__.CustomError

>>> raise CustomError("An error occurred")
Traceback (most recent call last):
...
__main__.CustomError: An error occurred
Posted by: Guest on June-29-2021

Python Answers by Framework

Browse Popular Code Answers by Language