Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to catch NotImplementedError Exception in Python?

 NotImplementedError is derived from RuntimeError. Which methods should raise this exception when they require derived classes to override the method in user defined classes?.


1 Answer
Rajendra Dharmkar

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.

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'>
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.