A programmer-defined exception class.,,import mathc
A programmer-defined exception class.,,import mathc
import mathclass NegativeNumberError( ArithmeticError ): passdef squareRoot( number ): if number < 0: raise NegativeNumberError, 'Square root of negative number not permitted' return math.sqrt( number )while 1: try: userValue = float( raw_input( '\nPlease enter a number: ' ) ) print squareRoot( userValue ) # 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
- Simple exception handling example,exceptionhandling,nu
- Demonstrates handling exceptions,,# try/except
- Power calculation,powercalculation,print 2L **
- Print rounds,printrounds,num = 1 / 3.
- Start 10 copies of a function running in parallel,copi
- Serialized by the mutex lock,serializedmutex,import th
热门文章:
相关内容
- Simple exception handling example,exceptionhandling,number1 = ra
- Demonstrates handling exceptions,,# try/except
- Power calculation,powercalculation,print 2L **
- Print rounds,printrounds,num = 1 / 3.
- Start 10 copies of a function running in parallel,copiesparallel,im
- Serialized by the mutex lock,serializedmutex,import threa
- Getting Child Nodes,gettingchildnodes,from xml.dom
- Child Nodes Can Be Text,childnodes,from xml.dom
- Searching Is Actually Recursive,searchingrecursive,from xml.dom
- Parsing XML from a URL,parsingxml,import urlli
评论关闭