Add exception handling to some of the functions for testing.