Runtime errors vs. logic errors

Kind of a nitpicky C++ thing, but shouldn’t argument checks on the
access code in gr_correlate_access_code_tag_bb.cc throw
std::invalid_argument or std::range_error, which are both derived from
std::runtime_error, versus std::out_of_range, which is derived from
std::logic_error? My understanding is that the latter is used for cases
such as referencing index 11 in a string that was declared to have
length 10, etc, whereas the former are used for checking user-supplied
parameters. A quick " find. | xargs grep out_of_range" yields the
attached output. It looks like the uses in
/src/lib/swig/guile/std_vector.i are correctly used (popping from an
empty vector, referencing an out-of-bounds index, etc.) but the other
cases should be invalid_argument. Thoughts? If this gets the go-ahead,
I’ll make a patch sometime this week.

Thanks,
Sean

Sorry for the re-post; forgot to include the attachment.

From: discuss-gnuradio-bounces+sean.nowlan=removed_email_address@domain.invalid
[mailto:discuss-gnuradio-bounces+sean.nowlan=removed_email_address@domain.invalid] On
Behalf Of Nowlan, Sean
Sent: Sunday, April 15, 2012 9:01 PM
To: [email protected]
Subject: [Discuss-gnuradio] runtime errors vs. logic errors

Kind of a nitpicky C++ thing, but shouldn’t argument checks on the
access code in gr_correlate_access_code_tag_bb.cc throw
std::invalid_argument or std::range_error, which are both derived from
std::runtime_error, versus std::out_of_range, which is derived from
std::logic_error? My understanding is that the latter is used for cases
such as referencing index 11 in a string that was declared to have
length 10, etc, whereas the former are used for checking user-supplied
parameters. A quick " find. | xargs grep out_of_range" yields the
attached output. It looks like the uses in
/src/lib/swig/guile/std_vector.i are correctly used (popping from an
empty vector, referencing an out-of-bounds index, etc.) but the other
cases should be invalid_argument. Thoughts? If this gets the go-ahead,
I’ll make a patch sometime this week.

Thanks,
Sean

On Sun, Apr 15, 2012 at 9:02 PM, Nowlan, Sean
[email protected] wrote:

/src/lib/swig/guile/std_vector.i are correctly used (popping from an empty
vector, referencing an out-of-bounds index, etc.) but the other cases should
be invalid_argument. Thoughts? If this gets the go-ahead, Ill make a patch
sometime this week.

Thanks,

Sean

Sean,
Sure, this makes sense. You’re right that it’s a bit nit-picky, but
you’re technically correct, and we might as well attempt to be as
correct as possible whenever we can. We’ll wait for your patch, but
probably apply it off of the master HEAD branch to go into 3.6.1.

Thanks,
Tom