i

Python Programming

Python Built-in Exceptions

Python also allows you to create your exceptions by deriving classes from standard built/in exceptions.

Here is example related to RuntimeError. Here class is created that is sub-class from RuntimeError. In the try block, the userdefined exception raised and caught in except block. The variable is used to create instance of class Network-errorr.

class Networkerrorr(RuntimeError):

   def __init__(self, args):

      self.args = args

try:

   raiseNetworkerrorr("Bad hostname")

except Networkerrorr,e:

   print(e.args)