better error handling, raise the correct exception