Catch ZeroDivisionError in is_constant

Fixes https://github.com/sympy/sympy/issues/7426