handle and raise the appropriate exceptions