mentis vulgaris
simple thoughts | jason smith
Exceptions are Easy. Except when they’re not.
Posted by Jason Smith - 10/02/10 at 09:02:10 amAssuming all the code compiles correctly, is Foo.Load() exception safe? Is there anything I need to change in Load’s exception handler to insure an instance of Foo is always in a valid state?
///Defines a type that associates a URI with the
/// count of frobs, miscellaneous information about those frobs
/// and where to get them.
///
public class Foo
{
public Foo()
{
Miscellaneous = new Dictionary<string , object>();
}
private Uri _infoSource;
public Uri InfoSourceUri
{
get { return _infoSource; }
set
{
_infoSource = value;
Load();
}
}
private void Load()
{
ServiceProxy<IFooConfig> proxy = null;
try
{
proxy = ServiceHelper.CreateProxyFromServiceContractInf<IFooConfig>(InfoSourceUri.ToString());
IFooConfig config = proxy.ProxyContract;
NumberOfFrobs = config.NumberOfFrobs;
WhereToGetThem = config.FrobSource;
for (var e in config.MiscellaneousEntries)
{
Miscellaneous.Add(e);
}
}
catch (Exception ex)
{
// Report the error
}
finally
{
proxy.CleanupProxy(); // Extension method that aborts if proxy is
// faulted or ignores if null
}
}
public int NumberOfFrobs { get; set; }
public Uri WhereWeGetThem { get; set; }
public IDictionary<string , object> Miscellaneous { get; private set; }
}
February 10, 2010 | In Software Development | 1 Comment
1 Comment »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.
[...] a previous post, I posed two questions to my readers (all √(-1) of them): whether a body of code was exception [...]
Pingback by mentis vulgaris » Exceptions are Easy. Except When They’re Not (Part 2) — March 2, 2010 #