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

    Raising Exceptions in HttpApplication.Init

    Urs Eichmann, Feb 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,032
    Urs Eichmann
    Feb 13, 2006
  2. NavyJay
    Replies:
    5
    Views:
    291
    NavyJay
    Apr 2, 2005
  3. Christoph Zwerschke

    Re-raising exceptions with modified message

    Christoph Zwerschke, Jul 5, 2007, in forum: Python
    Replies:
    35
    Views:
    869
    Gabriel Genellina
    Jul 16, 2007
  4. Silfheed
    Replies:
    4
    Views:
    277
    Silfheed
    Aug 21, 2007
  5. Joe Van Dyk
    Replies:
    6
    Views:
    118
    Joe Van Dyk
    Oct 6, 2005
Loading...

Share This Page