Skip to content

Conversation

@DamianZaremba
Copy link
Contributor

@DamianZaremba DamianZaremba commented Mar 3, 2017

On Python2.7 this kind of works, on Python3.{5,6} it explodes:

python2.7
>>> data = 'something'
>>> raise 'Invalid data!', data
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: exceptions must be old-style classes or derived from BaseException, not str

>>> raise ValueError('Invalid data', data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: ('Invalid data', 'something')
python3.6
>>> data = 'something'
>>> raise 'Invalid data!', data
  File "<stdin>", line 1
    raise 'Invalid data!', data
                         ^
SyntaxError: invalid syntax

>>> raise ValueError('Invalid data', data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: ('Invalid data', 'something')

I might come back with some more 3.x compatibility items, but this is stopping the code even byte compiling!

Not 100% satisfied with the chosen exception, but it kind of makes sense for the purposes of the raise.

@DamianZaremba DamianZaremba changed the title Use an exception class with raising an exception Use an exception class when raising an exception Mar 3, 2017
@TimEvens
Copy link
Contributor

Thanks!

@TimEvens TimEvens merged commit 28c06ee into SNAS:master Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants