Skip to content

Instantly share code, notes, and snippets.

@philiplaureano
Created May 4, 2011 00:51
Show Gist options
  • Save philiplaureano/954554 to your computer and use it in GitHub Desktop.
Save philiplaureano/954554 to your computer and use it in GitHub Desktop.
public class SampleExceptionHandler : IExceptionHandler
{
public bool CanCatch(IExceptionHandlerInfo exceptionHandlerInfo)
{
return true;
}
public void Catch(IExceptionHandlerInfo exceptionHandlerInfo)
{
var exception = exceptionHandlerInfo.Exception;
Console.WriteLine("Exception caught: {0}", exception);
// This line tells LinFu.AOP to swallow the thrown exception;
// By default, LinFu will just rethrow the exception
exceptionHandlerInfo.ShouldSkipRethrow = true;
}
}
class Program
{
static void Main(string[] args)
{
// Hook the sample exception handler into the application
ExceptionHandlerRegistry.SetHandler(new SampleExceptionHandler());
var account = new BankAccount(100);
// Without LinFu's dynamic exception handling, the
// next line of code will cause the app to crash:
account.Deposit(100);
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment