How to catch NotImplementedError Exception in Python?


User-defined base classes can raise NotImplementedError to indicate that a method or behavior needs to be defined by a subclass, simulating an interface. This exception is derived from RuntimeError. In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method.

Example

import sys
try:
   class Super(object):
        @property
        def example(self):
            raise NotImplementedError("Subclasses should implement this!")
   s = Super()
   print s.example
except Exception as e:
    print e
    print sys.exc_type

Output

Subclasses should implement this!
<type 'exceptions.NotImplementedError'>

Updated on: 12-Feb-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements