Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper C++ exception handling #10

Closed
hirschenberger opened this issue Mar 27, 2024 · 5 comments · Fixed by #11
Closed

Proper C++ exception handling #10

hirschenberger opened this issue Mar 27, 2024 · 5 comments · Fixed by #11

Comments

@hirschenberger
Copy link
Collaborator

I have a problem with some code that has to reconfigure the exposure value after every grabbed image. To do this the grabbing must be stopped, value set, grabbing started...

The problem is, that occasionally the C++ code throws a GenICam_3_1_Basler_pylon::RuntimeException that can't be caught in rust and so my app panics.

I looked at the code and it seems, although fn float_node_set_value(node: &UniquePtr<CFloatParameter>, value: f64) -> Result<()>; returns a Result, it seems it's not really created on errors (exceptions) in the FFI code.

Wouldn't it make sense to try-catch all C++ FFI functions return a Result::Err value on exceptions to make the user handle the error in Rust-land?

@astraw
Copy link
Member

astraw commented Mar 27, 2024

Catching all C++ exceptions and translating them to a rust PylonError should happen, but evidently does not.

I notice some cruft which is apparently unused like the trycatch C++ function. It would be great to wire this up to work as you suggest.

@hirschenberger
Copy link
Collaborator Author

hirschenberger commented Mar 28, 2024

It seems as if cxx is doing all the magic of converting an exception to a Result when that trycatch template function is present: https://cxx.rs/binding/result.html

I tried it and it correctly catches and converts a Pylon::GeneicException.

So I think we only have to add that GenICam_3_1_Basler_pylon::RuntimeException and maybe other Pylon exceptions to that catch-chain.

Maybe also add a catch-all arm to be on the safe side.

EDIT: I'll try it out on the system that makes trouble

@hirschenberger
Copy link
Collaborator Author

GenICam_3_1_Basler_pylon::RuntimeException is an Alias for GenICam::RuntimeException which is derived from Pylon::GenericException. So one exception handler is sufficient.

@hirschenberger
Copy link
Collaborator Author

@astraw Can you please look at this, I'd need that fix in a project

@astraw
Copy link
Member

astraw commented May 27, 2024

Ahh, yes, thanks for the ping. I was very busy with stuff but they are settling down and I should be able to look at this in the next couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants