change the error handling to exceptions and error code.