added functionality to handle excepetions