Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > defining, raising and catching exceptions

Reply
Thread Tools

defining, raising and catching exceptions

 
 
Chris Hare
Guest
Posts: n/a
 
      08-05-2010

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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjusting the names of custom exceptions (since raising strings is deprecated) Silfheed Python 4 08-21-2007 10:16 PM
Re-raising exceptions with modified message Christoph Zwerschke Python 35 07-16-2007 05:14 PM
Raising Exceptions in HttpApplication.Init Urs Eichmann ASP .Net 2 02-13-2006 03:42 PM
raising exceptions across DRb and XMLRPC Joe Van Dyk Ruby 6 10-06-2005 08:11 PM
__init__ method and raising exceptions NavyJay Python 5 04-02-2005 02:23 PM



Advertisments