[Q] Are Exceptions used that much in practice?
Jerome Mrozak
goose at enteract.com
Tue Dec 12 19:46:27 EST 2000
I believe I've been misunderstood. The problem is not "can I write code
without handling exceptions" but rather "are exceptions used
voluntarily, rather than by compulsion".
An example of compulsion is java.lang.Integer.parseInt(), which throws a
NumberFormatException you *must* deal with or the program won't
compile. I'm aware of examples of Python such as (faking it here):
while 1:
try:
input = inputFileObject.readline()
catch EOF:
break
else:
process(input)
The point of the question is this -- is code like this sample a way of
exercising the try-catch, or is this an example of something I end up
doing all of the time because it is so much easier than the alternative?
Other posters to this question provided a fair sampling of examples.
Some, I'm disappointed to say, were, shall we say, not so supportive.
The long-range goal of my question is to determine for my satisfaction
whether it is worth while for me to spend my limited time pursuing
Python as a compliment to (whatever other skills I might have) or to go
with the apparently much greater flow and use those resources on Perl.
The 'exception' thing could be a determiner, esp. with nothing similar
in Perl, but only if I can use it in a *positive* way instead of just to
test a return value. Heck, Perl has 'die' for that kind of testing.
Thanks for your concern anyways.
Jerome.
Erik Max Francis wrote:
>
> Jerome Mrozak wrote:
>
> > I realize that Python allows me to catch exceptions. But being a
> > novice
> > I'm not sure if they are used much in the 'real world'.
> ...
> > Another way of putting it is, if the try-catch-else didn't exist would
> > anyone be terribly put out? (If not then the construct isn't much
> > used...)
>
> Yes. Yes. Yes.
>
> Anyone who has done substantial programming in Python, Java, or C++ has
> used exceptions extensively. If you haven't found a significant use for
> exceptions, then you're either writing extremely trivial programs (ones
> so trivial they cannot fail, which has to be _really_ trivial) or you're
> not handling error conditions properly. Truth be told, handling
> arbitrary error conditions properly is one of the more difficult things
> to do in computer science. Exceptions, although they require a
> significant change in the way you write code, make this a lot easier.
> Draft Standard C++ programming without exceptions was obnoxious.
>
> --
> Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
> __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
> / \ Love is not love which alters when it alteration finds
> \__/ William Shakespeare, _Sonnets_, 116
> Alcyone Systems' CatCam / http://www.catcam.com/
> What do your pets do all day while you're at work? Find out.
--
Jerome Mrozak "Never buy a dog and bark for yourself"
goose at enteract.com --"Slippery" Jim DiGriz
(the Stainless Steel Rat)
More information about the Python-list
mailing list