[
https://issues.apache.org/jira/browse/HDFS-7207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14172176#comment-14172176
]
Zhanwei Wang commented on HDFS-7207:
------------------------------------
Hi [~wheat9]
I got an issue when I tried to add error message into {{Status}}.
I first want to add {{std::string}} into {{Status}} to keep the error message.
{code}
class Status {
public:
....
private:
int code;
std::string errormsg;
}
{code}
Since {{Status}} is passed by value in the API as return value, copying a
string may throw {{std::bad_alloc}} and it is very bad to the application.
So I tried another way. Only keep a string pointer in {{Status}}
{code}
class Status {
public:
....
private:
int code;
const char * errormsg; //point to a static thread local buffer
}
{code}
But this way also has issue since user may keep many instances of {{Status}}
but only the last instance keep the correct error message.
{code}
Status retval1 = fs.doSomething();
Status retval2 = fs.doSomething(); //Now, retval1 keep the incorrect error
message, since it is overwritten by retval2.
{code}
Any comments?
> libhdfs3 should not expose exceptions in public C++ API
> -------------------------------------------------------
>
> Key: HDFS-7207
> URL: https://issues.apache.org/jira/browse/HDFS-7207
> Project: Hadoop HDFS
> Issue Type: Sub-task
> Reporter: Haohui Mai
> Assignee: Colin Patrick McCabe
> Priority: Blocker
> Attachments: HDFS-7207.001.patch
>
>
> There are three major disadvantages of exposing exceptions in the public API:
> * Exposing exceptions in public APIs forces the downstream users to be
> compiled with {{-fexceptions}}, which might be infeasible in many use cases.
> * It forces other bindings to properly handle all C++ exceptions, which might
> be infeasible especially when the binding is generated by tools like SWIG.
> * It forces the downstream users to properly handle all C++ exceptions, which
> can be cumbersome as in certain cases it will lead to undefined behavior
> (e.g., throwing an exception in a destructor is undefined.)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)