[Python-bugs-list] [ python-Bugs-675928 ] Have exception arguments keep their type

SourceForge.net noreply@sourceforge.net
Tue, 28 Jan 2003 07:52:46 -0800


Bugs item #675928, was opened at 2003-01-28 01:06
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=675928&group_id=5470

Category: Python Interpreter Core
Group: Feature Request
Status: Open
Resolution: None
Priority: 5
Submitted By: Brett Cannon (bcannon)
Assigned to: Nobody/Anonymous (nobody)
Summary: Have exception arguments keep their type

Initial Comment:
If you execute the following code::

try:
    raise Exception('a string')
except Exception, err:
    print type(err)

it prints out that ``err`` is a type 'instance'.  It would be nice if it returned the type of the actual argument (in this case, type 'str').

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2003-01-28 10:52

Message:
Logged In: YES 
user_id=31435

I'm a bit baffled by this, Brett:  when you instantiate a class, 
you can pass any number of arguments to its constructor.  
You happened to pass a single string argument when building 
an instance of Exception here, but you could have passed 
any number of arguments.  Why should the first argument be 
special?  (Or maybe you think the last argument should be 
special <wink>).  Or what if you didn't pass any arguments at 
all?

Having "the detail" bound to the instance object raised is a 
feature, and a major one.

If you're in the habit of passing a single string to Exception 
directly, note that you can already get it back via doing

    str(err)

in the "except" clause.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=675928&group_id=5470