CSC148H1 Lecture Notes - List Of Unit Testing Frameworks, Exception Handling, 1.-Class Torpedo Boat
katrinasavvy and 38715 others unlocked
1
CSC148H1 Full Course Notes
Verified Note
1 document
Document Summary
Exceptions: try and except conditions: if the code under try statements works, skips the except condition, if error occurs, python compares error raised to exception typed specified by the except. A match = execute except block: ex, try, x = 1/0, except exception as error: # except exception catches all exceptions, print error # error message raised in the try block. Throw very specific exception in lower levels of program, catch only at higher level. Raise exceptions: if x == 0, raise exception( x is zero", more specific exception, def divide(top, bottom), if bottom == 0, raise valueerror( divisor is zero", else, return top / bottom. Only one error rasied at a time: ex, assert 3 == 4, assert 1 == 5, one failure, assert error in the first line. Raise called exits current program and gives error. Options: nose (separate install, but doesn"t use classes, pyunit/unittest (comes with python!, doctest (comes with python!)