1


Here is my code

try:
     raise UserError(_('foo'))
except Exception as e:
     raise UserError(_(str(e)))

The warning box shows (u'foo', None) instead of foo.

Warning
(u'foo', None)

[OK]

But exception shows correctly
Example

try:
     print 100 / 0
     raise UserError(_('foo'))
except Exception as e:
     raise UserError(_(str(e)))

Result is

Warning
integer division or modulo by zero
[OK]

This Problem is only inside the try. Please tell me what can I do?

Shameem
  • 2,664
  • 17
  • 21

1 Answers1

0

I solved by parse_tuple() function.

# ...
except Exception as e:
    parsed = parse_tuple(e)
    if parsed:
        raise UserError(_(str(parsed[0])))
    raise UserError(_(str(e)))

EDIT:

raise UserError(e.args[0])
Shameem
  • 2,664
  • 17
  • 21