Added more detailed exception handling as per Josh's commit comment.