OiO.lk Blog python python custom exception not being caught
python

python custom exception not being caught


I have created an exception like this

class MyException(Exception):
    """
    myexception
    """

and then the code is like :

 try:
        _, _, test = test_str.rpartition("/")
        return test
    except MyException:
        print(
            f'An error occurred while transforming')
    return test_str

When the code is executed with test_str = None, the exception is not caught. If I replace MyException with Exception, it works as expected. What’s the issue ?

If I replace MyException with Exception, it works as expected.



You need to sign in to view this answers

Exit mobile version