Template10 icon indicating copy to clipboard operation
Template10 copied to clipboard

Exception handling in SettingsService

Open jp-weber opened this issue 4 years ago • 3 comments

Currently possible exceptions are not directly handled and caught in the SettingsService. Would it be better to handle them here?

example Settings/Adapters/LocalFileSettingsAdapter.cs new

        public (bool successful, string result) ReadString(string key)
        {
            if (_container.Values.ContainsKey(key))
            {
                return (true, _container.Values[key].ToString());
            }
            else
            {
                return (false, string.Empty);
            }
        }

old

public string ReadString(string key)
            => _container.Values[key].ToString();

I have already implemented many things in my fork: https://github.com/jp-weber/Template10/tree/master/Source/Template10.Extras/Services/Settings

jp-weber avatar Jun 27 '20 15:06 jp-weber

@jp-weber how about creating a repo dedicated to Settings? Windows-XAML/Template10.SettingsService. Interested? THe many things you have already done are pretty handy for developers and we could brand it Template 10 and pub to Nuget.

JerryNixon avatar Sep 15 '20 15:09 JerryNixon

@JerryNixon Yes I would like to do that 😀

jp-weber avatar Sep 18 '20 16:09 jp-weber

I wonder if bool TryRead<T>(string key, out T value) would be a better signature.

JerryNixon avatar Jun 23 '21 20:06 JerryNixon