T
Torsten
Hello,
I'am currently wrapping a c-style library for using a camera and I am
not sure, how to handle errors.
The API of the camera has functions for sending commands to the camera
and querying the cameras response from the camera:
int write(void* handle, char* command, long timeout)
int read(void* handle, char** response, size_t buffersize, long timeout)
Both return an error code, since the commands can fail for several
reasons that are not in the scope of the programmer (camera timeout,
camera not connected, ...).
No I want to wrap this library. A member function of the camera shall
send a command to the camera and return it's response, e.g.
std::string Camera::sendCommand(const std::string &command);
My question: what is the best way to handle these errors:
1. Throw exceptions and wrap every sendCommand in a try/catch block?
This makes the calling code quite ugly.
2. Provide an error() function, that can be called after sending the
command?
3. Make the reponse an output parameter and return an error code?
bool sendCommand(const std::string &command, std::string &response);
Can someone give me an advice?
Thanks, Torsten
I'am currently wrapping a c-style library for using a camera and I am
not sure, how to handle errors.
The API of the camera has functions for sending commands to the camera
and querying the cameras response from the camera:
int write(void* handle, char* command, long timeout)
int read(void* handle, char** response, size_t buffersize, long timeout)
Both return an error code, since the commands can fail for several
reasons that are not in the scope of the programmer (camera timeout,
camera not connected, ...).
No I want to wrap this library. A member function of the camera shall
send a command to the camera and return it's response, e.g.
std::string Camera::sendCommand(const std::string &command);
My question: what is the best way to handle these errors:
1. Throw exceptions and wrap every sendCommand in a try/catch block?
This makes the calling code quite ugly.
2. Provide an error() function, that can be called after sending the
command?
3. Make the reponse an output parameter and return an error code?
bool sendCommand(const std::string &command, std::string &response);
Can someone give me an advice?
Thanks, Torsten