Python and checked exceptions

Discussion in 'Python' started by Kay Schluehr, Sep 23, 2006.

  1. Kay Schluehr

    Kay Schluehr Guest

    A new cookbook recipe suggesting two decorators @throws and @catches
    for treatment of checked exceptions in Python:

    http://aspn.activestate.com/ASPN/Cookbook/Python/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
     
    Kay Schluehr, Sep 23, 2006
    #1
    1. Advertising

  2. Kay Schluehr

    Peter Otten Guest

    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/Cookbook/Python/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.ZeroDivisionError) -> 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
     
    Peter Otten, Sep 23, 2006
    #2
    1. Advertising

  3. In message <>, 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/Cookbook/Python/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.
     
    Lawrence D'Oliveiro, Sep 23, 2006
    #3

  4. >> 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
     
    Diez B. Roggisch, Sep 23, 2006
    #4
  5. Kay Schluehr

    Kay Schluehr Guest

    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/Cookbook/Python/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.ZeroDivisionError) -> 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
     
    Kay Schluehr, Sep 23, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yurps
    Replies:
    1
    Views:
    6,901
    rajeshthangarasu1983
    Feb 29, 2008
  2. Wendy S
    Replies:
    0
    Views:
    1,822
    Wendy S
    Feb 18, 2004
  3. Ahmed Moustafa
    Replies:
    5
    Views:
    30,042
    Chris Smith
    Jul 14, 2004
  4. exquisitus
    Replies:
    4
    Views:
    8,352
    Patricia Shanahan
    May 6, 2005
  5. Harold Yarmouth

    Callbacks and checked exceptions

    Harold Yarmouth, Oct 27, 2008, in forum: Java
    Replies:
    15
    Views:
    670
    Harold Yarmouth
    Oct 30, 2008
Loading...

Share This Page