Re: RFC: (in head) Throws()?

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Tue, 14 Oct 2008 14:12:14 +1300 (NZDT)

> On Mon, Oct 13, 2008 at 1:26 PM, Amos Jeffries <squid3_at_treenet.co.nz>
> wrote:
>> Kinkie wrote:
>>>
>>> Hi all.
>>>
>>> I've recently found myself battlign with a certain difficulty in
>>> formatting custom messages for thrown exceptions; in order to use
>>> TextExceptions properly I'd have to set a stringstream up, fill it in,
>>> get a c_str out and then Throw, leaking memory in the meantime because
>>> the message would be double-copied and there'd be no reachable code to
>>> free one of the copies. The current Throw() implementation is very
>>> skewed towards servicing Must().
>>>
>>> All of this should be easily solvable by defining a Throws() macro
>>> (possibly with an accompanying Musts call) which would offer semantics
>>> similar to debugs(), and get rid of this wart in one easy sweep.
>>>
>>> Any opinions?
>>>
>>
>> Um I don't see what your problem is. Or what you are trying to do.
>>
>> To me it looks like is highly geared around non-dependable char* and
>> Must()
>> is warped to fit TextException.
>>
>> "TextException::TextException(msg)"
>> can take a local char buffer[], "constant string", or object.c_buf().
>> it does xstrdup() and xfree() it properly on its own.
>
> Maybe it's me not seeing the obvious.
>
> How would you render an exception saying
> "out of bounds (trying to access index X of Y)"
> where X and Y are off_t 's?

{
  char temp[256];
  snprintf(temp,256,"out of bounds (trying to access index %"PRId64" of
%"PRId64")", X, Y);
  Throw(temp,__FILE__,__LINE__);
}

Amos
Received on Tue Oct 14 2008 - 01:12:17 MDT

This archive was generated by hypermail 2.2.0 : Tue Oct 14 2008 - 12:00:05 MDT