fi
 }
 
+catch()
+{
+       local exit_code=$1
+       local exit_status_file="${OUTPUT_DIR}/${EXIT_STATUS_FILE}"
+       # This is just a cleanup and the directory may
+       # have already been unmounted. So, don't let this
+       # clobber the error code we intend to return.
+       unmount_image || true
+       if [[ -f "${exit_status_file}" ]]; then
+               exit_code="$(cat ${exit_status_file})"
+       fi
+       exit ${exit_code}
+}
+
 main()
 {
        local script_dir="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
        done
        shift $((OPTIND -1))
 
+       trap 'catch "$?"' EXIT
+
        if [[ $# -eq 0  && "${debug_shell}" == "no" ]]; then
                echo "No command specified, will run ${DEFAULT_COMMAND} in the vm"
        else
        fi
 }
 
-catch()
-{
-       local exit_code=$1
-       local exit_status_file="${OUTPUT_DIR}/${EXIT_STATUS_FILE}"
-       # This is just a cleanup and the directory may
-       # have already been unmounted. So, don't let this
-       # clobber the error code we intend to return.
-       unmount_image || true
-       if [[ -f "${exit_status_file}" ]]; then
-               exit_code="$(cat ${exit_status_file})"
-       fi
-       exit ${exit_code}
-}
-
-trap 'catch "$?"' EXIT
-
 main "$@"