reducing if statements and error handling
jhardcastle at solarc.com
Tue Aug 21 15:08:28 CEST 2001
Another easy newbie question here... Suppose I have a method that
accepts a string (called 'value') as an argument. I want the method
to check to see if the contents of the string is all numbers. Here's
print 'success: ' + value + ' is a valid entry'
print 'error: ' + value + ' is NOT a valid entry'
1) can I reduce this "if" logic down to one statement, perhaps using
2) is there a recommended approach for throwing errors? In this case,
I'd want to throw an error if the text is not a number and stop
processing. Can I define a custom exception to do that? Should I
catch the error in the logic that called the method and throw the
exception there if the method returns a "-1", or should I throw the
More information about the Python-list