RusticiSoftware / SCORMCloud_NetLibrary

A C# library to assist in the integration of the SCORM Cloud service into .Net 2.0+ applications.
http://scorm.com/scorm-solved/scorm-cloud/develop-a-scorm-cloud-app/
Other
11 stars 22 forks source link

Advice on Try/Catch handling #13

Open cemerson opened 9 years ago

cemerson commented 9 years ago

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: