Added some exception handling.

Added some exception handling.