Change throw(badarg) to exit(badarg) for error handling.