TypeError:exceptions must be old-style classes or derived from BaseException, not str
You can't raise
a str
. Only Exception
s can be raise
d.
So, you're better off constructing an exception with that string and raising that. For example, you could do:
test = 'abc'if True: raise Exception(test + 'def')
OR
test = 'abc'if True: raise ValueError(test + 'def')
Hope that helps