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!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 16 Jan 2007 00:03:46 -0600 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Structured exception information References: X-Newsreader: Tom's custom newsreader Message-ID: Date: Tue, 16 Jan 2007 00:03:46 -0600 NNTP-Posting-Host: 67.164.83.70 X-Trace: sv3-0gUHETYe+/DyTo7mMT//3HlOG+cgrQcyq6n2Cg+h6C747MWv8xg9S24fb0f2jPRT61DQLuHOQuVNgby!og+FZx67uzl95UFycxiN1+lRTwMfQJsSoRoRfEewOdeBF4SFiwfdPc6D1tZs5/m/AlT0cCXXj4Nq!e8GmExSb9z3e/w== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:8156 Date: 2007-01-16T00:03:46-06:00 List-Id: > You could have: > > procedure My_Own_Raise (E : in Ada.Exceptions.Exception_ID; > Info : Extra_Info); > > and the implementation could encode Info as a String, and use that as > the Message passed to Raise_Excpetion. The handler then decodes the > String. The stream attributes could be used for encoding/decoding. > Maybe wrapping this mess in some generics could make it more type safe. > > Yuck. You could make it type safe with an extended tagged record. Make a key handler that saves a pointer to the classwide record, returning a "safe deposit key" whose (short) 'image constitutes the message. Risking posting untried pseudo code, how about: package exception_info is exception_with_info : exception; type base_type is abstract tagged record actual_occurrence : ada.exceptions.exception_occurrence_access; end record; procedure handle(x : in out base_type); -- Called by handler for descendant of base type. Does a Free -- on x.actual_occurrence type p_exception_info_type is access base_type'class; procedure raise_with_info(p : in p_exception_info_type); -- Trades the pointer to the information for a unique key from a -- (protected) key handler, then raises Exception_With_Info -- with key_type'image(key) as the message string. function fetch_info(egad : ada.exceptions.exception_occurrence) return p_exception_info_type; -- Extracts the key_type'value from the message, gives it to -- the protected key handler, and returns the saved pointer. and to use declare ... type speeding_ticket_type is new exception_info.base_type with record time : ada.calendar.time; speed : positive; end record; procedure handle(ticket : in out speeding_ticket_type) is begin ada.text_io.put_line(integer'image(ticket.speed) & " mph." & ada.exceptions.exception_information(ticket.actual_occurrence.all)); handle(exception_info.base_type(ticket)); end handle; ... when there's an exception that needs to pass speeding ticket info do when oops:constraint_error => declare p : exception_info.p_exception_info_type := new speeding_ticket_type( actual_occurrence=>ada.exceptions.save_occurrence(oops), time=>ada.calendar.clock, speed=>speedometer_value); begin exception_info.raise_with_info(p); end; and the catcher is when aha:exception_info.exception_with_info => declare p : exception_info.p_exception_info_type := exception_info.fetch(aha); begin handle(p.all'class); free(p); end;