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

Advice on Try/Catch handling #13

Open
cemerson opened this issue Feb 2, 2015 · 0 comments
Open

Advice on Try/Catch handling #13

cemerson opened this issue Feb 2, 2015 · 0 comments

Comments

@cemerson
Copy link
Contributor

cemerson commented Feb 2, 2015

Could you advise on how you'd propose users of this library handle errors in API calls with try/catch blocks?

For example - I'd rather not have to use the RegistrationExists() call before calling the GetLaunchHistory() to avoid making 2 API calls instead of one. So, if I call GetLaunchHistory and the registrationId I use is not found/invalid, I'd rather it fall into the try/catch and just keep moving on. Would you advise for or against this approach?

Here's a snippet of how I might try altering the GetLaunchHistory call - is this a bad idea or ok with you?

    public List<LaunchInfo> GetLaunchHistory(string registrationId)
    {
        try {            
            ServiceRequest request = new ServiceRequest(configuration);
            request.Parameters.Add("regid", registrationId);
            XmlDocument response = request.CallService("rustici.registration.getLaunchHistory");
            XmlElement launchHistory = ((XmlElement)response.GetElementsByTagName("launchhistory")[0]);
            return LaunchInfo.ConvertToLaunchInfoList(launchHistory);    
        } catch (Exception ex) {
            // error! just return an empty list?
            return new List<LaunchInfo>();
        }

    } 

Related API calls:

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

1 participant