   "Whether to confirm when applying fixit on line."
   :group 'ycmd
   :type 'boolean)
+
+(defcustom ycmd-after-exception-hook nil
+  "Function to run if server request resulted in exception.
+
+This hook is run whenever an exception is thrown after a ycmd
+server request.  Two arguments are passed to the function, a
+string with the type of request that triggerd the exception and
+the server response structure which looks like this:
+
+  ((exception
+    (TYPE . \"RuntimeError\"))
+   (traceback . \"long traceback string\")
+   (message . \"Can't jump to definition.\"))
+
+This variable is a normal hook.  See Info node `(elisp)Hooks'."
+  :group 'ycmd
+  :type 'hook
+  :risky t)
 
 (defconst ycmd--diagnostic-file-types
   '("c"

       :parser 'json-read
       :sync sync))))

(defun ycmd--handle-exception (results)
  "Handle exception in completion RESULTS.

This function handles `UnknownExtraConf', `ValueError' and
`RuntimeError' exceptions."
  (let-alist results
    (pcase .exception.TYPE
      ("UnknownExtraConf"
       (ycmd--handle-extra-conf-exception .exception.extra_conf_file))
      ((or "ValueError" "RuntimeError")
       (ycmd--handle-error-exception .message)))))

(defun ycmd--send-request (type success-handler)
  "Send a request of TYPE to the `ycmd' server.

Otherwise the response is probably an exception."
  (if (and (not (vectorp results))
           (assq 'exception results))
      (ycmd--handle-exception "NotifyParse" results)
    (ycmd--report-status 'parsed)
    (run-hook-with-args 'ycmd-file-parse-result-hook results)))

