Example: Handling Constructor Failure

The following example demonstrates error handling when the constructor fails.

import PT_DIAGNOSTICS:*;

class TestFailedConstructor extends PTDiagnostics
   /* Constructor */
   method TestFailedConstructor();
   /* Public Method */
   method GetDiagnosticInfo();
   method IsPlugIn();
private
   instance boolean &constructorFailed;
end-class;

method TestFailedConstructor
   Local boolean &status;
   Local string &sError;
   %Super = create PTDiagnostics();
   &status = %Super.SetProperty(%This, "Purpose", "String",
 "This is a diagnostic to show how developers can trap a failure
 in the constructor and print out results to the web page.");
   /* introduce unknown propName of Where1 rather than Where */
   &status = %Super.SetProperty(%This, "Where1", "Boolean", True);
   If Not &status Then
      %This.constructorFailed = True;
   Else
      %This.constructorFailed = False;
   End-If;
end-method;

method GetDiagnosticInfo
   Local string &sError, &sLicenseCode, &sLicenseGroup;
   Local boolean &status;
   If %This.constructorFailed Then
      &status = %Super.InsertData("String", "Status Failed!",
 "This message will be printed out in the HTML page if something
 fails in the constructor.  This is expected behaviour.");
   Else
      SQLExec("SELECT LICENSE_CODE, LICENSE_GROUP FROM PSOPTIONS",
 &sLicenseCode, &sLicenseGroup);
      &status = %Super.InsertData("String",
 "Your License Code is: ", Upper(&sLicenseCode));
   End-If;
end-method;

method IsPlugIn
end-method;