Python and Flaming Thunder

Dave Parker daveparker at flamingthunder.com
Wed May 28 11:09:42 EDT 2008


> > If catch(set x to y+z.) < 0.1 then go to tinyanswer.
>
> So what does this do exactly if the set throws an error?

I think the catch should catch the error thrown by set, compare it to
0.1, the comparison will not return true because the error is not less
than 0.1, and so the go-to to tinyanswer will not be taken.

> Is the error
> message printed at the top level going to be telling you about the failed
> addition or the failed comparison?

I don't think there will be an error message at the top in the case
above, because I don't think the comparison should fail -- the
comparision will return that it is not true that the error is less
than 0.1.

> Why do you need the catch anyway, if a
> statement is just an expression why can't you just put the statement into
> parentheses?

Statements return values, but statements are not just expressions.
Statements are more about control-flow and side-effects; expressions
are more about returning values.  Putting a statement into parentheses
in a context where expressions are also allowed in parentheses is (or
can be) both lexically and visually ambiguous.  That's why C had to
resort to the confusing "=" vs "==" notation -- to disambiguate the
two cases.  The "catch" keyword unambiguously alerts the reader that
the parenthesis contain a statement (or a whole list of statements).

> For that matter, is there any way to distinguish between different errors
> and only catch particular ones?

I think the catch function should catch all of the errors (and the non-
error result if no error occured), so I think distinguishing the error
would have to come after.  Maybe something like:

Set result to catch(read x from "input.txt".).
If result = dividebyzeroerror then ... else throw result.

I'm open to alternate suggestions, though.

> You have a great opportunity to avoid making some of the same mistakes that
> Python is trying to get out of.

I'm sure that I'll make my own new and different errors. :)  However,
I really appreciate your comments because maybe I'll make fewer
errors.  Or at least, correct them faster.

On May 28, 7:52 am, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> Dave Parker <davepar... at flamingthunder.com> wrote:
> > Catch also gives you a
> > single, uniform, syntactically unambiguous way to embed statements (or
> > whole statement lists) into expressions -- without causing the
> > syntactic problems of = statements in if statements or the obfuscation
> > of question mark notation, etc.  For example:
>
> > If catch(set x to y+z.) < 0.1 then go to tinyanswer.
>
> So what does this do exactly if the set throws an error? Is the error
> message printed at the top level going to be telling you about the failed
> addition or the failed comparison? Why do you need the catch anyway, if a
> statement is just an expression why can't you just put the statement into
> parentheses?
>
> For that matter, is there any way to distinguish between different errors
> and only catch particular ones? A bare except clause in Python is usually a
> signal of bad code: when handling errors you only want the errors you have
> anticipated, and want to be sure that any unexpected errors don't get
> caught.
>
> You have a great opportunity to avoid making some of the same mistakes that
> Python is trying to get out of. For example as of Python 2.5
> KeyboardInterrupt and SystemExit to longer inherit from Exception. That
> means a bare except in Python no longer catches either of those: if you
> want to handle either of these exceptions you have to be explicit about it.
>
> --
> Duncan Boothhttp://kupuguy.blogspot.com




More information about the Python-list mailing list