Errors

Implementations of custom errors

source

MyException

 MyException (message)

Common base class for all non-exit exceptions.

try:
    x = float('kjsd')
except MyException('custom error') as e:
    print(e)
#     raise MyException("cannot divide by zero")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [21], in <cell line: 1>()
      1 try:
----> 2     x = float('kjsd')
      3 except MyException('custom error') as e:

ValueError: could not convert string to float: 'kjsd'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Input In [21], in <cell line: 1>()
      1 try:
      2     x = float('kjsd')
----> 3 except MyException('custom error') as e:
      4     print(e)

TypeError: catching classes that do not inherit from BaseException is not allowed