Monday 15 June 2015

Get Values Of Method On Throws Exceptions in C# -



Get Values Of Method On Throws Exceptions in C# -

i work on logging project. want save parameter values of methods in database. how can these values. want parameter value of "test" method in firstchanceexception event.

class programme { private static void main(string[] args) { appdomain.currentdomain.firstchanceexception += currentdomain_firstchanceexception; test(100); } private static void test(int i) { throw new overflowexception(); } private static void currentdomain_firstchanceexception(object sender, system.runtime.exceptionservices.firstchanceexceptioneventargs e) { //i want parameter value of test method } }

you can postsharp:

[serializable] public class exceptionpolicyattribute : onexceptionaspect { public override void onexception(methodexecutionargs args) { guid guid = guid.newguid(); trace.traceerror("exception {0} handled exceptionpolicyattribute: {1}", guid, args.exception.tostring()); throw new internalexception( string.format("an internal exception has occurred. utilize id {0} " + "for farther reference issue.", guid)); } }

the parameter methodexecutionargs contains parameter values passed failing method call.

c# exception logging exception-handling aop

No comments:

Post a Comment