python custom errors

Solutions on MaxInterview for python custom errors by the best coders in the world

showing results for - "python custom errors"
Jacopo
22 Mar 2019
1class MyException(Exception):
2  """You can put code here"""
3  pass
4
5class MyOtherException(MyException):
6  """You can also put code here"""
7  pass
Erika
13 Jul 2018
1>>> class CustomError(Exception):
2...     pass
3...
4
5>>> raise CustomError
6Traceback (most recent call last):
7...
8__main__.CustomError
9
10>>> raise CustomError("An error occurred")
11Traceback (most recent call last):
12...
13__main__.CustomError: An error occurred