```
public class Solution {
public int reverse(int x) {
int res = 0;
do {
try {
res = Math.addExact(Math.multiplyExact(res, 10), x % 10);
}catch(ArithmeticException e) {
return 0;
}
x /= 10;
}while(x != 0);
return res;
}
}
```