adding correct exit codes for caught exceptions

Using the begin/rescue pattern prevents the parent shell from receiving an exit code that's indicative of any errors that occurred while running the script.