Python and checked exceptions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kay Schluehr

    Python and checked exceptions

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



    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

  • Peter Otten

    #2
    Re: Python and checked exceptions

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

    >
    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 UncheckedExcept ionError(except ions.ZeroDivisi onError) -OK
    Raises ZeroDivisionErr or -OK
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "checked_except ions.py", line 134, in test
    test4(3,2)
    UnboundLocalErr or: local variable 'test4' referenced before assignment

    Peter

    Comment

    • Lawrence D'Oliveiro

      #3
      Re: Python and checked exceptions

      In message <1159009493.872 015.33880@d34g2 000cwd.googlegr oups.com>, Kay
      Schluehr wrote:
      A new cookbook recipe suggesting two decorators @throws and @catches
      for treatment of checked exceptions in Python:
      >

      >
      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.

      Comment

      • Diez B. Roggisch

        #4
        Re: Python and checked exceptions

        >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
        RuntimeExceptio ns.

        Why do you call them semi-mandatory?

        diez

        Comment

        • Kay Schluehr

          #5
          Re: Python and checked exceptions

          Peter Otten wrote:
          Kay Schluehr wrote:
          >
          A new cookbook recipe suggesting two decorators @throws and @catches
          for treatment of checked exceptions in Python:



          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 UncheckedExcept ionError(except ions.ZeroDivisi onError) -OK
          Raises ZeroDivisionErr or -OK
          Traceback (most recent call last):
          File "<stdin>", line 1, in ?
          File "checked_except ions.py", line 134, in test
          test4(3,2)
          UnboundLocalErr or: local variable 'test4' referenced before assignment
          >
          Peter
          Thanks, I fixed this.

          Kay

          Comment

          Working...