!standard 11.4.1 (3) 00-12-11 AI95-00241/02 !class binding interpretation 00-11-19 !status ARG Approved 9-0-1 00-11-19 !status work item 00-10-04 !status received 00-10-04 !priority Medium !difficulty Easy !subject Testing for Null_Occurrence !summary The function Exception_Identity applied to Null_Occurrence returns Null_Id which can then be tested using the equality operation. !question Ada.Exceptions exports the constant Null_Occurrence, but doesn't provide any way to test whether a given exception occurrence is Null_Occurrence (type Exception_Occurrence is limited). Is this intended? (No.) !proposal The call Exception_Identity(X) where X has the value Null_Occurrence should not raise Constraint_Error but return the value of Null_Id which can then be tested against Null_Id using the equality operation. !wording Replace 11.4.1(14) by Raise_Exception and Reraise_Occurrence have no effect in the case of Null_Id or Null_Occurrence. Exception_Name raises Constraint_Error for a Null_Id. Exception_Message, Exception_Name, and Exception_Information raise Constraint_Error for a Null_Occurrence. Exception_Identity applied to Null_Occurrence returns Null_Id. !discussion When logging information, an application probably will use Null_Occurrence to represent the absence of an exception. When displaying the log, it is necessary to determine whether a particular occurrence is Null_Occurrence, or an occurrence containing information about an exception. Currently, it is difficult to test for Null_Occurrence because, being of a limited type, it is not possible to compare with the constant Null_Occurrence. Moreover, the function Exception_Identity applied to Null_Occurrence raises Constraint_Error. An exception handler can be used to detect this but it is awkward, does not reflect that this is a normal case, and potentially can mask other errors. Two alternatives were considered. One was to add a function Is_Null_Occurrence and the other was to define Exception_Identity to return Null_Id when applied to Null_Occurrence rather than raise Constraint_Error. The second approach was taken because it avoids adding a further function and moreover it seems unnatural that Exception_Id(Null_Occurrence) should raise Constraint_Error. An instance of Null_Occurrence can be tested for as in the following: procedure Process_Exception(X: Exception_Occurrence) is begin if Exception_Identity(X) = Null_Id then -- process the case of a Null_Occurrence else -- process other exception occurrences end if; end; !corrigendum 11.4.1(14) @drepl Raise_Exception and Reraise_Occurrence have no effect in the case of Null_Id or Null_Occurrence. Exception_Message, Exception_Identity, Exception_Name, and Exception_Information raise Constraint_Error for a Null_Id or Null_Occurrence. @dby Raise_Exception and Reraise_Occurrence have no effect in the case of Null_Id or Null_Occurrence. Exception_Name raises Constraint_Error for a Null_Id. Exception_Message, Exception_Name, and Exception_Information raise Constraint_Error for a Null_Occurrence. Exception_Identity applied to Null_Occurrence returns Null_Id. !ACATS test Add a test case to CB41004 to check that Exception_Identity(Null_Occurrence) does return Null_Id. !appendix !topic Testing for Null_Occurrence !reference RM95-11.4.1(3) !from Gary Dismukes (for Ada Core Technologies) !keywords Ada.Exceptions, Null_Occurrence !discussion Ada.Exceptions exports the constant Null_Occurrence, but doesn't provide any way to test whether a given exception occurrence is Null_Occurrence (type Exception_Occurrence is limited). We propose that a function should be added to Ada.Exceptions that would allow testing whether an exception occurrence is Null_Occurrence. In GNAT, we have added a child function Ada.Exceptions.Is_Null_Occurrence for this purpose: -- This is a GNAT-specific child function of Ada.Exceptions. It provides -- clearly missing functionality for its parent package, and most reasonably -- would simply be an added function to that package, but this change cannot -- be made in a conforming manner. function Ada.Exceptions.Is_Null_Occurrence (X : Exception_Occurrence) return Boolean; -- This function yields True if X is Null_Occurrence, and False otherwise **************************************************************** From: Tucker Taft Sent: Friday, September 22, 2000 9:19 PM I believe the original intent was that: Exception_Identity(Null_Occurrence) = Null_Id providing a mechanism for testing for Null_Occurrence, but I see that 11.4.1(14) contradicts that by indicating that Exception_Identity raises Constraint_Error in this case. I think that is a mistake, though others might remember otherwise. > function Ada.Exceptions.Is_Null_Occurrence > (X : Exception_Occurrence) > return Boolean; > -- This function yields True if X is Null_Occurrence, and False otherwise This seems like a reasonable proposal, in any case, although it is obviously an amendment, not an interpretation. **************************************************************** From: Robert Dewar Sent: Friday, September 22, 2000 10:03 PM <> Well I would be happy to allow this identity, though this would be a change (in GNAT we could add a child, but not change clear RM semantics), but if one is in the amendment business, perhaps allowing the above identity is the cleanest approach. ****************************************************************