On 06/25/2012 12:48 AM, Steven D'Aprano wrote:
On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote:

But what I wanted was to catch any exception.
Be careful of what you ask for, since you might get it.

"Catch any exception" is almost certainly the wrong thing to do, almost
always. The one good reason I've seen for a bare except is to wrap the
top level of an application in order to redirect uncaught exceptions to
something other than the console (such as a GUI error dialog box). And
even then, you probably don't want to catch *all* exceptions, but only
those that inherit from Exception:

try:
     main()  # run my application
except Exception as err:
     display_error_dialog(err)
     # or log to a file, or something...



This time it was the right thing, as I suspected that *SOME* exception was being thrown, but had no idea what one. The problem was I didn't know how to print the result when I caught the exception. This has since been cleared up, but first I found it on Google, and then I was told about it on the list. The documentation left me totally ... well, not uninformed, but confused. As I said it turned out to be a method call on an uninitialized variable, as I found out once I figured out how to list the result of catching the exception. Which is what I expected the documentation to show me how to do.

The comments on the list have been vastly helpful, even if they still tend to assume that I know more than I do. (And even if some of them seem to be a bit ... off. E.g., suggesting that I generate the exception on purpose so I can find out what it is, when I started off with no idea as to WHAT the problem was.)

What really annoys me is the way the documentation has worsened since python 2.5, but if you know what it is trying to tell you, then I guess you aren't bothered by undefined terms and lack of examples. I went away from programming in Python for a couple of years though, and I guess I missed the transition, or something.

--
Charles Hixson

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to