Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python and checked exceptions

Reply
Thread Tools

Python and checked exceptions

 
 
Kay Schluehr
Guest
Posts: n/a
 
      09-23-2006
A new cookbook recipe suggesting two decorators @throws and @catches
for treatment of checked exceptions in Python:

http://aspn.activestate.com/ASPN/Coo.../Recipe/498131

This might be of practical interest for some and theoretical interest
for others - in particular those who know checked ex as a language
feature of Java.

Regards,
Kay

 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      09-23-2006
Kay Schluehr wrote:

> A new cookbook recipe suggesting two decorators @throws and @catches
> for treatment of checked exceptions in Python:
>
> http://aspn.activestate.com/ASPN/Coo.../Recipe/498131
>
> This might be of practical interest for some and theoretical interest
> for others - in particular those who know checked ex as a language
> feature of Java.


Probably not what you wanted:

>>> test()

Raises UncheckedExceptionError(exceptions.ZeroDivisionErr or) -> OK
Raises ZeroDivisionError -> OK
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "checked_exceptions.py", line 134, in test
test4(3,2)
UnboundLocalError: local variable 'test4' referenced before assignment

Peter
 
Reply With Quote
 
 
 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      09-23-2006
In message <. com>, Kay
Schluehr wrote:

> A new cookbook recipe suggesting two decorators @throws and @catches
> for treatment of checked exceptions in Python:
>
> http://aspn.activestate.com/ASPN/Coo.../Recipe/498131
>
> This might be of practical interest for some and theoretical interest
> for others - in particular those who know checked ex as a language
> feature of Java.


The trouble with having to declare every possible exception that a function
might throw is that it rapidly turns into a complete mess. That's why such
declarations are optional in C++, and only semi-mandatory in Java.
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      09-23-2006

>> This might be of practical interest for some and theoretical interest
>> for others - in particular those who know checked ex as a language
>> feature of Java.

>
> The trouble with having to declare every possible exception that a
> function might throw is that it rapidly turns into a complete mess. That's
> why such declarations are optional in C++, and only semi-mandatory in
> Java.


I agree with you that they are a mess, and I usually wrap them
RuntimeExceptions.

Why do you call them semi-mandatory?

diez
 
Reply With Quote
 
Kay Schluehr
Guest
Posts: n/a
 
      09-23-2006
Peter Otten wrote:
> Kay Schluehr wrote:
>
> > A new cookbook recipe suggesting two decorators @throws and @catches
> > for treatment of checked exceptions in Python:
> >
> > http://aspn.activestate.com/ASPN/Coo.../Recipe/498131
> >
> > This might be of practical interest for some and theoretical interest
> > for others - in particular those who know checked ex as a language
> > feature of Java.

>
> Probably not what you wanted:
>
> >>> test()

> Raises UncheckedExceptionError(exceptions.ZeroDivisionErr or) -> OK
> Raises ZeroDivisionError -> OK
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "checked_exceptions.py", line 134, in test
> test4(3,2)
> UnboundLocalError: local variable 'test4' referenced before assignment
>
> Peter


Thanks, I fixed this.

Kay

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Callbacks and checked exceptions Harold Yarmouth Java 15 10-30-2008 07:26 AM
CheckBox Checked=false when checked in DataList yurps ASP .Net 1 02-29-2008 01:08 PM
Checked and unchecked exceptions. A clearer explanation please. exquisitus Java 4 05-06-2005 12:09 PM
Checked exceptions vs unchecked exceptions Ahmed Moustafa Java 5 07-14-2004 01:46 PM
Tomcat and checked/unchecked exceptions Wendy S Java 0 02-18-2004 10:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57