/*
* @author DenizPiri / denizpiri@hotmail.com
* @author Valentin Simonov / http://va.lent.in/
*/
using System;
using UnityEngine;
namespace TouchScript.Utils
{
///
/// Extension methods for event handling.
///
public static class EventHandlerExtensions
{
///
/// Invokes an event handling exceptions.
///
/// EventArgs type.
/// Event.
/// Event sender.
/// EventArgs.
/// The exception caught or null.
public static Exception InvokeHandleExceptions(this EventHandler handler, object sender, T args)
where T : EventArgs
{
try
{
handler(sender, args);
}
catch (Exception ex)
{
Debug.LogException(ex);
return ex;
}
return null;
}
///
/// Invokes an event handling exceptions.
///
/// Event.
/// Event sender.
/// EventArgs.
/// The exception caught or null.
public static Exception InvokeHandleExceptions(this EventHandler handler, object sender, EventArgs args)
{
try
{
handler(sender, args);
}
catch (Exception ex)
{
Debug.LogException(ex);
return ex;
}
return null;
}
}
}