I always get the following error message:

Runtime Error Message: Line 53: TypeError: exceptions must be old-style classes or derived from BaseException, not str

Last executed input: "-2147483648"

My code:

```
class Solution:
# @return an integer
valid_numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
INT_MAX = 2147483647
INT_MIN = 2147483648
def atoi(self, str):
neg = False
if len(str) == 0:
return 0
i = 0
while (str[i] == ' '):
i += 1
if i > len(str) - 1:
return 0
if str[i] == '+' or str[i] == '-':
i += 1
if str[i-1] == '-':
neg = True
j = i
while(j < len(str)):
if str[j] not in self.valid_numbers:
break
j += 1
if i == j:
return 0
conv = 0
for k in range(i, j):
digit = ord(str[k]) - ord('0')
if not neg:
if self.INT_MAX -digit >= 10*conv:
conv = conv * 10 + digit
else:
return self.INT_MAX
if neg:
if self.INT_MIN - digit >= 10*conv:
conv = conv * 10 + digit
else:
return -self.INT_MIN
return conv if not neg else -conv
```