A programmer-defined exception class. : Exception Class : Exception : Python examples (example source code) Organized by topic

C++
PHP
Python
Python Home »  Exception   » [  Exception Class  ]  Screenshots 
 



A programmer-defined exception class.



import math

class NegativeNumberErrorArithmeticError ):
   pass

def squareRootnumber ):
   if number < 0:
      raise NegativeNumberError, "Square root of negative number not permitted"
   return math.sqrtnumber )

while 1:
   try:
      userValue = floatraw_input"\nPlease enter a number: " ) )
      print squareRootuserValue )
   float raises ValueError if input is not numerical
   except ValueError:
      print "The entered value is not a number"
   # squareRoot raises NegativeNumberError if number is negative
   except NegativeNumberError, exception:
      print exception
   else:
      break

           
       
Related examples in the same category
1.  User-defined Exceptions: Name their own exceptions by creating a new exception class User-defined Exceptions: Name their own exceptions by creating a new exception class
2.  Create a base class for exceptions defined by a module
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.