Handle error cases raising exceptions where necessary.