Created
May 4, 2011 00:51
-
-
Save philiplaureano/954554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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