Write a program in Python or Java to reverse the digits of a given integer while handling edge cases.