defining, raising and catching exceptions

Discussion in 'Python' started by Chris Hare, Aug 5, 2010.

  1. Chris Hare

    Chris Hare Guest

    I have a block of test code, where I am trying to raise and catch my own user defined exception

    class NetActiveError(RuntimeError):
    def __init__(self,error):
    self.args = error

    def a():
    try:
    fh = open("me.txt", "r")
    except Exception as (errno, errText):
    print errText
    try:
    b()
    except NetActiveError as (errono, errText):
    print errno, errText

    def b():
    print "def b"
    raise NetActiveError,"net already running"


    a()


    When I run it though, I get the following error:

    chare$ python z
    No such file or directory
    def b
    Traceback (most recent call last):
    File "z", line 20, in <module>
    a()
    File "z", line 12, in a
    except NetActiveError as (errono, errText):
    ValueError: too many values to unpack


    What am I doing wrong here?
     
    Chris Hare, Aug 5, 2010
    #1
    1. Advertisements

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

    Raising Exceptions in HttpApplication.Init

    Urs Eichmann, Feb 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,127
    Urs Eichmann
    Feb 13, 2006
  2. Adam H. Peterson

    Try blocks and not catching exceptions

    Adam H. Peterson, Jan 27, 2004, in forum: C++
    Replies:
    8
    Views:
    531
    Andrey Tarasevich
    Jan 27, 2004
  3. NavyJay
    Replies:
    5
    Views:
    409
    NavyJay
    Apr 2, 2005
  4. Christoph Zwerschke

    Re-raising exceptions with modified message

    Christoph Zwerschke, Jul 5, 2007, in forum: Python
    Replies:
    35
    Views:
    1,022
    Gabriel Genellina
    Jul 16, 2007
  5. Silfheed
    Replies:
    4
    Views:
    369
    Silfheed
    Aug 21, 2007
  6. Joe Van Dyk
    Replies:
    6
    Views:
    187
    Joe Van Dyk
    Oct 6, 2005
  7. Reto Schuettel

    Raising my own exceptions with DRb

    Reto Schuettel, Jan 23, 2006, in forum: Ruby
    Replies:
    1
    Views:
    201
    Eric Hodel
    Jan 23, 2006
  8. dkmd_nielsen
    Replies:
    1
    Views:
    139
    Robert Klemme
    Nov 7, 2008
Loading...