Skip to content

Instantly share code, notes, and snippets.

@cartermp
Last active November 6, 2015 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartermp/84d78268130e02aa6251 to your computer and use it in GitHub Desktop.
Save cartermp/84d78268130e02aa6251 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YES
{
public abstract class ErrorReportingBase
{
public ErrorReportingBase(ErrorOccurredHandler handler)
{
this.ErrorOccurred += handler;
}
public event ErrorOccurredHandler ErrorOccurred;
public delegate void ErrorOccurredHandler(Exception ex);
/// <summary>
/// Raises the error so that it can be handled by the controlling class.
/// </summary>
/// <param name="ex">The ex.</param>
/// <returns><c>true</c> if the error handler was set and called successfully; otherwise false.</returns>
internal bool RaiseErrorOccurred(Exception ex)
{
bool handled = false;
if (this.ErrorOccurred != null)
{
try
{
this.ErrorOccurred(ex);
handled = true;
}
catch (Exception error)
{
ApplicationLogger.Log(System.Diagnostics.TraceEventType.Error, "Error while trying to handle an exception.", error);
}
}
return handled;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment