Raise the right exception depending on the error