I have two methods I'm working on. One saves and one loads. Obviously, both require some kind of error handling, so I implemented some “tricks of all processing”. Now the heel of the hunt, what happens next, is contextual for where, at runtime, an error occurs. Because of this, I would like to handle the error in the caller, one level higher. Thus, I may have different logic for different situations.
An example is. If I check the load on the first run and it does not work, I can assume that their memory may be cleared. But if I try to load at runtime, I can assume that the memory was not cleared (by the right means), and there should be something.
public void SaveToStorage(AccountCollection Collection) { try { var storage = IsolatedStorageSettings.ApplicationSettings; storage["defaultCollection"] = Collection; storage.Save(); } catch (Exception ex) { // Do something meaningful here } } public AccountCollection LoadFromStorage() { try { AccountCollection collection; var storage = IsolatedStorageSettings.ApplicationSettings; storage.TryGetValue("defaultCollection", out collection); return collection; } catch (Exception ex) { // Do something meaningful here } return null; }
Essentially, I ask if I can make the error to the caller, but still keep the original error information.
EDIT: Both John and Andrew gave the correct answers. Andrew will get a green checkmark as I would like to do some other general cleanings in the original class.
source share