|
Boost Users : |
From: gast128 (gast128_at_[hidden])
Date: 2007-03-05 04:58:20
David Abrahams <dave <at> boost-consulting.com> writes:
> I don't know what "guarded with exception safety" means. You
> certainly don't need try/catch blocks everywhere.
> ...
> Writing exception-safe code is not really any harder than writing code
> that's correct in the presence of errors with any other
> error-reporting mechanism. In fact, given a clear understanding of
> how to use exceptions effectively, they are less tricky to use
> correctly than other approaches to error handling, because they
> provide a high-level abstraction that lets you concentrate on what
> matters.
Hello David,
my point is that exceptions are fatal when not dealt with. This can be a good
thing in case of fatal exceptions (e.g. memory exhaustion), but bad when the
exceptions are not that severe (e.g. string length on a NULL string).
Another item is that I think that one of the rationales is that it is cleaner
to write code like:
void Foo()
{
try
{
//write logic
}
catch ()
{
//write exception case(s)
}
}
This throwing ctor stuff can be annoying if one considers the follwing case:
void GetAllEmployees()
{
std::vector<Employee> v;
Employee e = Load(...)
v.push_back(e);
//etc.
}
consider that one of the employees can 'become' corrupt. But still the rest of
the employees should be dealt with. With exception handling it becomes:
void GetAllEmployees()
{
std::vector<Employee> v;
try
{
Employee e = Load(...)
v.push_back(e);
}
catch ()
{
}
//etc.
}
No more nice seperation between logic and exception.
wkr,
me
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net