different behaviour for user defined exception with attribute args

V

Visco Shaun

Hi all

For an exception defined as below

class OptionError(Exception):
def __init__(self, args):
self.args = args
def __str__(self):
return repr(self.v)

an iteration is happening when the exception is raised

Meanwhile for almost the same structured exception replacing the
attribute 'args' with say 'value' it is not a probs.

class OptionError(Exception):
def __init__(self, args):
self.value = args
def __str__(self):
return repr(self.value)

This was frustrating because for a st. OptionError('Error') for
exception 1 output will be

OptionError: ('E', 'r', 'r', 'o', 'r')

Meanwhile for exception 2 output will be

OptionError: 'Error'

which is desired..Why this behaviour?

Regards
Visco
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top