• Exception handling e.g. Database.FTSearch

    By Markus Langer 4 years ago

    How can I catch an exception?

    My code:

    String query = 'xxxxxx';//xxxxxx is a placeholder for the real query Database db = XSPUtil.getCurrentDatabase(); DocumentCollection addressCollection = db.FTSearch(query);

    The org.openntf.log contains the exception

    ….
    NotesException: Notes error: Query is not understandable (xxxxxx)
    ….

    How can I catch the information about “Query is not undestandable” in my code to present it to the user?

    Thanks a lot
    Markus

    • By Paul S Withers 4 years ago

      Have you got an OpenLog database set up? If so, the code incorporated from XPages OpenLog Logger (XspOpenLogItem class) will call addFacesMessage(), which writes the message back to the browser.

      All the settings in XPages OpenLog Logger are valid for ODA as well, so xsp.openlog.filepath can be used to change the OpenLog path

      • By Markus Langer 4 years ago

        At the moment I don't have a database attached. Is there no other way?

        • By Paul S Withers 4 years ago

          Add a try/catch block in your code. If there's an error, call

          FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage()));
          DominoUtils.handleException(e);

          The first line is effectively what the XspOpenLogItem is doing. “e” will be your Exception or Throwable. You could add that code into a static utility method, for regular usage.

          • By Markus Langer 4 years ago

            Many thanks for your support.
            I already have a try/catch block but the function db.FTSearch doesn't throws the exception to my code.