Created
January 6, 2016 01:21
-
-
Save The-Quill/6787ead18e0c6bd66e12 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
namespace Test1 | |
{ | |
public class Utils | |
{ | |
public static object InvokeAndCatchError(Delegate del, object parameters, params object[] optionalParameters) | |
{ | |
try | |
{ | |
return del.Method.Invoke(parameters, optionalParameters); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception occured:"); | |
Console.WriteLine(e); | |
return null; | |
} | |
} | |
public static string Foo(string bar) | |
{ | |
return bar + bar; | |
} | |
public delegate object Del(string bar); | |
public Utils(string lorem) | |
{ | |
Del handler = Foo; | |
InvokeAndCatchError(handler, lorem); //Returns TargetException | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment