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():
    fh = open("me.txt", "r")
    except Exception as (errno, errText):
    print errText
    except NetActiveError as (errono, errText):
    print errno, errText

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


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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.