From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,699cc914522aa7c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Structured exception information From: Georg Bauhaus In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: # Message-ID: <1169819196.5976.57.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Date: Fri, 26 Jan 2007 14:46:36 +0100 NNTP-Posting-Date: 26 Jan 2007 14:46:37 CET NNTP-Posting-Host: 90ceb3e4.newsspool3.arcor-online.net X-Trace: DXC=dK>cdFU[@VHj7E:bke<5HFMcF=Q^Z^V3H4Fo<]lROoRAgUcjd<3m<;B^@^?JcUT=dIPCY\c7>ejVHd7LPVKjQ1DLm`I]8jhO6mK X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8605 Date: 2007-01-26T14:46:37+01:00 List-Id: On Fri, 2007-01-26 at 04:35 -0500, Stephen Leake wrote: > So the code in the analog module looks something like: > ... > if User_Volts > Max_Volts then > raise User_Error with > Real_Type'image (User_Volts) & > " greater than " & > Real_Type'image (Max_Volts); > else > Write_Hardware (Module.Hardware_Device, To_Counts (User_Volts)); > end if; I'd prefer something like procedure Write_Output (Module : in Module_Type; Symbol : in Symbol_Access_Type) is User_Volts : constant Real_Type := Reals.Get (Symbol); begin if User_Volts > Max_Volts then View.Set_Error((Off_Error with Condition => Greater_Than, Required => Max_Volts, Given => User_Volts)); raise User_Error; else Write_Hardware (Module.Hardware_Device, To_Counts (User_Volts)); end if; end Write_Output; And then exception when E : User_Error => View.Show_Error; -- Uses the interface of the progenitors of Off_Error, -- for the object entered using View.Set_Error. -- If we had exception types, this could be -- much simpler, just View.Show_Error(E). View.Print(Ada.Exceptions.Get_Exception_Message (E)); end; > What would you change about this, and why? Absent exception types, making exception info propagation explicit will add some advantages, in addition to not being implicit as in exception strings: - message information isn't dependent on arbitrary strings in the implementation of Write_Output. You'd need to recompile a *validation* procedure when the *message* should change even though the validation didn't change. From this viewpoint Write_Output mixes two separate concerns: input checking and UI message construction. - Off_Error is derived from an abstract data type describing failure information. A user of this type can choose a suitable message constructed from the information. This is both *MVC* and also *decoupling*: The procedure Write_Output can be used unchanged even when error messages are to be displayed using Wide_String, a pair of LEDs or a Spanish character set. The construction of a message that meets the UI criteria (the parser loop with prompt in this case) becomes the job of the a View package that matches the display. - the program points the reader to the software types and modules involved in propagating error information by naming the package and type at both ends (View in this case). A change in the implementation of View won't necessitate a recompilation of Write_Output, unlike using raise ... with ... for message construction. - Any useful information that compilers add for an exception occurrence will not be touched.