Hi again!
This post seeks well explained opinions about the further
outlined approach of using exceptions. It's presumed that
nothing more than just the type of exception may be used to
influence the further code execution in a program, yet for
debugging purposes it might be helpful to have code doing
some checking and throwing informative exceptions. This
could be used by iterators, access functions etc.
Sort of this:
1 2
|
if (mMap.find(keyRef) == mMap.end())
throw EXCN::LOGIC::out_of_range(__FILE__, __LINE__, why);
| |
Extensible exception hierarchy:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
namespace EXCN
{
using namespace EXCN_impl;
typedef EXCN_impl::base<ST> base;
typedef excn_template<ST,cs_logic::logic> logic;
namespace LOGIC
{
typedef excn_subtemplate<
ST,logic,cs_logic::out_of_range>
out_of_range;
}
}
| |
Adding a new exception takes at least declaring a global
char const what_of_the_new_exception[] and adding it to the
above hierarchy.
what() of an excn_template or excn_subtemplate gives just
something like "logic > out_of_range", while why() may
provide a detailed description of the cause. + file() and
line() functions.
Maybe it's just a choice between something like a mystical
segfault and an ugly, but informative exception:
catch (EXCN::base &e) { e.report_cerr(); exit(1); }