[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Stylistic question about constructing error messages
From: |
Greg Chicares |
Subject: |
Re: [lmi] Stylistic question about constructing error messages |
Date: |
Fri, 12 Feb 2016 23:12:36 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0 |
On 02/12/2016 02:01 PM, Vadim Zeitlin wrote:
>
> There are many checks for the input data in the SOA tables code that I'm
> writing and each of them throws an exception if it fails. Most of them also
> try to provide as much information as possible about what exactly went
> wrong because nothing is more aggravating than running a command merging
> in a hundred of files and getting "invalid data" error without any more
> details. So a typical check looks like this:
>
> if(num > max_num)
> {
> std::ostringstream oss;
> oss << "value for numeric field '"
> << name
> << "' is out of range (maximum allowed is "
> << max_num
> << ") at line "
> << line_num
> ;
> throw std::runtime_error(oss.str());
> }
Ultimately I anticipate integrating this into lmi, where I'd prefer to use
lmi's fatal_error() instead...
fatal_error()
<< "Value for numeric field '"
<< name
<< "' is out of range (maximum allowed is "
<< max_num
<< ")."
<< LMI_FLUSH // A macro, yes, but a minimal, unavoidable one.
;
> So far so good, but there are _many_ of them. I was writing all the checks
> in full so far because I wanted to keep things simple, but this is getting
> really tiresome, so I'd like to ask you what do you think about some
> alternatives, i.e. to choose from
Of the ideas presented, I like the macro-based ones least, and I think
you do, too. Your favorite was this:
> throw make_error<std::runtime_error>
> ("value for numeric field '"
> ,name
> ,"' is out of range (maximum allowed is "
> ,max_num
> ,") at line "
> ,line_num
> );
But isn't that almost identical to to the fatal_error() version above?
- [lmi] Stylistic question about constructing error messages, Vadim Zeitlin, 2016/02/12
- Re: [lmi] Stylistic question about constructing error messages,
Greg Chicares <=
- Re: [lmi] Stylistic question about constructing error messages, Vadim Zeitlin, 2016/02/12
- Re: [lmi] Stylistic question about constructing error messages, Greg Chicares, 2016/02/13
- Re: [lmi] Stylistic question about constructing error messages, Vadim Zeitlin, 2016/02/13
- Re: [lmi] Stylistic question about constructing error messages, Greg Chicares, 2016/02/13
- Re: [lmi] Stylistic question about constructing error messages, Vadim Zeitlin, 2016/02/13
- Re: [lmi] Stylistic question about constructing error messages, Greg Chicares, 2016/02/14
- Re: [lmi] Stylistic question about constructing error messages, Vadim Zeitlin, 2016/02/14
- Re: [lmi] select tables terminology (was: Stylistic question about constructing error messages), Vadim Zeitlin, 2016/02/14
- Re: [lmi] select tables terminology, Greg Chicares, 2016/02/15
- Re: [lmi] select tables terminology, Vadim Zeitlin, 2016/02/15