Error handling

I referred to Questions on “Stack Overflow”.