Re: [PyOpenGL-Users] Have exceptions terminate glutMainLoop
Brought to you by:
mcfletch
|
From: Richard J. <ric...@op...> - 2001-10-07 07:13:15
|
On Sun, 7 Oct 2001 17:01, Mike C. Fletcher wrote:
> So each handler needs to be something like:
This code should appear anywhere you are passing control from your code to
somewhere else that could raise an exception. Unless you're _absolutely_
certain it'll never raise that exception. Anything else is just ... I dunno,
"fuzzy" programming. I just can't imagine not handling ... a late packet, or
a loose dongle, or ...
You don't quit, you handle the exception and alert the user "hey, your
dongle's fallen out" or "hey, the network's getting a bit congested".
> def x( a,b ):
> try:
> try:
> doWhatever
> except (X,Y,MemoryError, IOError): # expected error conditions
> pass
> finally:
> cleanup() # handle restoring state
>
> vs
>
> def x( a,b ):
> try:
> doWhatever
> finally:
> cleanup() # handle restoring state
That's exactly what I believe are good programming practices. Mind you,
catching MemoryError and "pass"ing looks very, very dodgy to me :)
> It's possible to define "safe wrapper" functions that share that
> exception-catching code, I suppose. Sigh. My reaction is based on my
> experiences as a user where, for instance, 3DSMax dumps out because the
> dongle got knocked loose, or Tiberean Sun decides to end the whole game
> because 1 packet was received too late (timeout exception doesn't get
> caught, so the entire program exits, dumping hours of play), or where setup
> scripts bomb because a single callback wasn't received due to an unexpected
> condition (too many mice on the system, or C drive isn't available, or
> sockets can't be initialised). I suppose those (recent) experiences have
> tainted my vision.
There's a lot of baaad code out there that has a _lot_ to answer for in terms
of lowering user expectations. Python's exception model is a cinch to use,
and we should use it properly :)
> I will bow to general opinion on this one, as I can see lots of "rigor"
> benefits, but from experience with OpenGLContext using PyGame (where an
> exception in a handler actually kicks you out of the main loop), I've not
> really found the functionality that pleasant to work with. I'm not really
> a "rigor" programmer, suppose I'll have to learn.
>
> If we are going to raise something, can we raise the last Python exception,
> instead of SystemExit?
That'd be nice, but if the gluMainLoop can't be quit, then we're kinda stuck
there.
> I don't really like the environmental variables approach. It makes code
> harder to share, since code with one assumption won't readily fit into
> another. Rather learn to write straight-jacket code than have a split in
> coding styles like that.
I agree on those grounds - it'd be a bad approach.
Richard
|