Exception Handling

The PeopleSoft Search Framework uses the try/catch exception construct to handle special conditions that interrupt normal program execution. When special runtime conditions are encountered, the PeopleSoft Search Framework will construct and throw objects of the Exception class or some class derived from the Exception class. There are two main categories of PeopleSoft Search Framework exceptions:

  • Those thrown when the PeopleSoft Search Framework detects a special condition.

  • Those thrown when the search provider responds with anything other than what was expected for the given request.

The second category of exceptions is necessarily search engine specific since these are coming from the search provider. For example, there are three exception classes defined in the PT_SEARCH:SESIMPL:EXCEPTION subpackage: SESQueryServiceException, SESAdminServiceException, and SESSearchAttributeException. These exception classes may expose SOAPFaultCode and SOAPFaultString properties that are returned by the search engine. The implementation of Elasticsearch as a search provider relies on this PT_SEARCH:SESIMPL:EXCEPTION subpackage.

Virtually all methods of all classes in the PeopleSoft Search Framework can throw an exception; therefore, Oracle recommends that you put all calls to the PeopleSoft Search Framework classes within try-catch blocks.

The following example builds on the previous example that processed search results. In this example, the results processing is augmented by try-catch exception handling:

import PT_SEARCH:*;

/* instantiate and initialize the query object */
/* ...                                         */
/* execute the query */
Local PT_SEARCH:SearchResultCollection &results;

   &results = &qry.Execute(&start, &size);
catch PT_SEARCH:SESIMPL:EXCEPTION:SESQueryServiceException &sesEx
   MessageBox(0, "", 0, 0, "The search could not be perfomed.");
   MessageBox(0, "", 0, 0, "The Search Provider returned an error.");
   MessageBox(0, "", 0, 0, "SOAP fault: ", &sesEx.SoapFaultString);
   WriteToLog(0, &sesEx.SoapFaultCode);
   WriteToLog(0, &sesEx.SoapFaultString);
catch Exception &psEx
   MessageBox(0, "", 0, 0, "The search could not be perfomed.");
   MessageBox(0, "", 0, 0, "Exception: ", &psEx.DefaultText);
   WriteToLog(0, &psEx.DefaultText);

/* process the results */
   Local number &docCount = &results.GetDocumentCount();
   Local number &hitCount = &results.GetEstimatedHitCount();

   Local PT_SEARCH:SearchResult &curResult;
   Local PT_SEARCH:SearchFieldCollection &customs;
   For &i = 1 To &results.GetDocumentCount()
      &curResult = &results.Item(&i);

      &score = &curResult.GetScore();
      &title = &curResult.GetTitle();
      &summary = &curResult.GetSummary();
      &lastMod = &curResult.GetLastModified();
      &url = &curResult.GetUrlLink();
      /* do something with the values */
      &customs = &curResult.GetCustomAttributes();
      If (&customs <> Null) Then
         /* iterate over custom fields of the result */
         For &j = 1 To &customs.Count()
            &name = &customs.Item(&j).Name;
            &value = &customs.Item(&j).Value;
            /* do something with the name/value pair */
catch Exception &ex
   /* encountered an exception while processing results */
   /* inspect the exception to determine appropriate action */