Handle exceptions in C bindings#2980
Handle exceptions in C bindings#2980MandelbrotInferno wants to merge 1 commit intof3d-app:masterfrom
Conversation
mwestphal
left a comment
There was a problem hiding this comment.
Please request a review whenever you need by using github review mechanism (top right).
Ah yes. I forgot to request that. Thanks for the heads up:) |
No worries, I'm just explaining the process as usual :) |
| f3d::log::error("Failed to allocate memory for char*: ", e.what()); | ||
| } | ||
|
|
||
| return nullptr; |
There was a problem hiding this comment.
please document that behavior
| } | ||
|
|
||
| if (out_count) | ||
| catch (const std::bad_alloc& e) |
There was a problem hiding this comment.
is that for the new ? im not sure we want to catch that. wdyt @Meakk @AoGao-Kedoka ?
There was a problem hiding this comment.
i also think it's unnecessary. If memory is full, the program is already in a critical state. The catch wouldn't help anyways.
There was a problem hiding this comment.
I'd say we should catch f3d specific exceptions, and fallback on a generic std::exception to catch the rest of them, so bad_alloc is too specific.
There was a problem hiding this comment.
I dont think we should catch all exceptions in all methods ?
At least thats not what we have been doing in other c bindings.
There was a problem hiding this comment.
As you see fit. I agree we should be consistent.
There was a problem hiding this comment.
lets not catch everthing, but only what we throw ( or can throw by our usages in the C binding)
| auto collapsed = f3d::utils::collapsePath(p, base); | ||
| return f3d_utils_strdup(collapsed.string()); | ||
| } | ||
| catch (...) |
There was a problem hiding this comment.
catch specific exceptions, not everything
| std::string regex = f3d::utils::globToRegex(glob, path_separator); | ||
| return f3d_utils_strdup(regex); | ||
| } | ||
| catch (const std::exception& e) |
There was a problem hiding this comment.
catch specific exceptions, not everything
mwestphal
left a comment
There was a problem hiding this comment.
I've only reviewed utils for now, to make sure we are on the same page regarding what is expected here.
Thanks! Will try to fix the mentioned issues. I did however notice that in some of the C bindings that exception handling was written for we handled everything eg: The above is in the engine_c_api.cxx file for example. Should I go ahead and modify those too in order to ensure only the required specific exceptions are handled? |
Engine is where everything getting initialized and it would be quite amount of work to be specific here. But I defer to @mwestphal |
Indeed, in that specific case, for the sake of simplicty and brevity we decided to catch everything, but its better to be specific when possible. |
Describe your changes
All of the C bindings for libf3d now handle exceptions inside of them and log the relevant warning/error message. Where necessary, I have also added the necessary descriptions in the C binding comments.
Issue ticket number and link if any
#2763
Checklist for finalizing the PR
.github/workflows/versions.json, I have updateddocker_timestampContinuous integration
\ci fast