lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Stylistic question about constructing error messages


From: Vadim Zeitlin
Subject: Re: [lmi] Stylistic question about constructing error messages
Date: Sat, 13 Feb 2016 02:51:00 +0100

On Fri, 12 Feb 2016 23:12:36 +0000 Greg Chicares <address@hidden> wrote:

GC> Ultimately I anticipate integrating this into lmi, where I'd prefer to use
GC> lmi's fatal_error() instead...
GC> 
GC>     fatal_error()
GC>         << "Value for numeric field '"
GC>         << name
GC>         << "' is out of range (maximum allowed is "
GC>         << max_num
GC>         << ")."
GC>         << LMI_FLUSH // A macro, yes, but a minimal, unavoidable one.
GC>         ;

 There are a couple of problems with using fatal_error(): first, it means
dealing with all the alert functions machinery (including ensuring that the
stuff is linked in and so on) which seems unnecessary for a simple command
line tool. Second, the code can throw different exceptions, at least
logic_error and invalid_argument as well as runtime_error and fatal_error()
only supports the latter. I guess I could just use runtime_error everywhere
but the two others seem more appropriate in the places where they're used...

GC> >  So far so good, but there are many of them. I was writing all the checks
GC> > in full so far because I wanted to keep things simple, but this is getting
GC> > really tiresome, so I'd like to ask you what do you think about some
GC> > alternatives, i.e. to choose from
GC> 
GC> Of the ideas presented, I like the macro-based ones least, and I think
GC> you do, too. Your favorite was this:
GC> 
GC> >         throw make_error<std::runtime_error>
GC> >             ("value for numeric field '"
GC> >             ,name
GC> >             ,"' is out of range (maximum allowed is "
GC> >             ,max_num
GC> >             ,") at line "
GC> >             ,line_num
GC> >             );
GC> 
GC> But isn't that almost identical to to the fatal_error() version above?

 The main two differences are the possibility to specify the class of the
exception and the absence of LMI_FLUSH: I don't think the location
information is really useful to the user of soa_tool and I don't like
specifying std::flush everywhere. Another minor difference is that the
"throw" keyword is explicit with this approach, which is, IMHO, a good
thing.

 I also admit that I have a dislike of fatal_error() due to its name: in
many cases, these exceptions are not fatal at all and can be dealt with by
the calling code if necessary.

 Do you think I should still use fatal_error() no matter these (perceived)
problems?

 Thanks,
VZ

reply via email to

[Prev in Thread] Current Thread [Next in Thread]