Hi everyone,
I'm actually trying to solve the question of error vs exception.
In my functions library, performance is not the key value. The realy important thing is to provide "easy to use interface".
For example, I have the following non-member non-friend function :
1 2 3 4 5 6
|
namespace process
{
kill(pid_type pid);
} //! namespace process
|
there is no pre-conditions to call this function, so, these errors can occur :
* pid does not exists
* permission denied
* cannot terminate process
Actualy, error are reported by throwing exceptions.
1 2 3 4 5 6 7 8
|
try
{
process::kill(pid);
}
catch (const boost::system::system_error& err)
{
//do something
}
|
But the user code is
becoming so littered with try-catch blocks as to be unmaintainable.
So, like the boost::filesystem V3,
I would like to provide a dual interface :
1 2
|
process::kill(pid_type pid); //throw
process::kill(pid_type pid, boost::system::error_code& error); //nothrow
|
I don't know what is the best design to provide both interfaces and don't repeat myself.
I thought about the following solutions :
unique higher interface :
1 2
|
process::kill(pid_type pid, boost::system::error_code* error = NULL);
//try...catch the original call and report by filling error argument if not null,
|
But I also have another idea :
Can a policy based design help here?
I mean : a kind of error-reporting policy...?
If it's possible, how does this kind of solution look like?
I prefer a full static solution than a dynamic one.
Thanks for your help!
--
valblade