I want to add an error reporting feature to my WPF app. I have the view for it created; I just need to know when to call it. I am used to web development and this is my first WPF app.
public static void Get<T>(Func<T> func, Action<BaseResult<T>> callback, bool report = false){
BaseResult<T> result;
try {
result = new BaseResult<T>(func());
}
catch (Exception ex){
if (report) new ErrorWindow(ex.Message).Show();
result = new BaseResult<T>(false, ex.Message);
}
callback(result);
}
The BaseResult
class stores the result if the call was successful and an error message if it isn't. Sometimes I don't want to report the result of the call to an error screen, sometimes I just want to know if the call was successful.
Does this violate Single Responsibility Principle?
This can't be the best way of implementing this. Has anyone done this before? My way seems overly complicated.