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

Error handling in SoapySDRPlay driver #19

Open
fventuri opened this issue Nov 26, 2020 · 1 comment
Open

Error handling in SoapySDRPlay driver #19

fventuri opened this issue Nov 26, 2020 · 1 comment

Comments

@fventuri
Copy link
Collaborator

This purpose of this discussion is to come up with a good way of handling errors in the SoapySDRPlay driver.

Part of this discussion is here: #16 (see posts by @vsonnier and @jketterl; @SDRplay and @guruofquality are also mentioned there).

To summarize that discussion there, one option could be to throw a std::runtime_error exception when an invalid value is requested in a 'set' function, and making sure that functions like listSampleRates() are consistent with the values acceptable by the corresponding 'set' function (i.e. setSampleRate() in this example), so that the SoapySDR client application knows which values and settings are valid in advance.

In a similar fashion an exception could possibly also be thrown if say a call to the underlying 'sdrplay_api' methods were to fail (for instance if the call to 'sdrplay_api_Update()' returned an error status code for some reason), since currently those return codes are ignored by the SoapySDRPlay driver in many cases.

Franco

@guruofquality
Copy link
Collaborator

recommendations or would be-specs by @guruofquality on which exceptions

Anything that inherits from std::exception. That way, we can reliably make exceptions and get their error messages. There are a lot of default exceptions to choose from: https://en.cppreference.com/w/cpp/error/exception But std::runtime_error is the most common

But honestly, there has never really been an attempt to differentiate between different errors thrown, ever. And the Soapy C API doesn't reflect this capability, and very very few writing exception handling code probably even want to do this.

So this code should catch all exceptions. I think anything not throwing exceptions that inherit from std::exception (inside of driver code) should probably just catch it and re-throw.

try
{
   sdr->setSampleRate(...);
}
catch (const std::exception &ex)
{
    std::cout << "oops " << ex.what() << std::endl;
}

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

No branches or pull requests

2 participants