Reflectionã«ããã¡ã½ããå¼ã³åºãæã®ä¾å¤
ã¡ãã£ã¨åµãã¾ããã
using System; class MyException : Exception {} class Foo { public void Bar() { throw new MyException (); } } static class Program { static void Main () { Foo foo = new Foo (); try { foo.Bar (); } catch (MyException) { Console.WriteLine ("Catch!"); } Type t = foo.GetType(); try { t.GetMethod("Bar").Invoke(foo, null); } catch (MyException) { Console.WriteLine ("Catch!"); } catch (System.Reflection.TargetInvocationException) { Console.WriteLine ("ãåã¯èª°ã !"); } } } /* çµæ Catch! ãåã¯èª°ã ! */
Reflectionçµç±ã ã¨ãã¡ã½ããå ã§çºçããä¾å¤ãTargetInvocationExceptionã§ã©ããããããã§ãããåä½ãã¹ãã§ã¯OKã ã£ãã³ã¼ããçµåãã¹ãã§NGã«ãªã£ã¦æ©ã¿ã¾ããã
大é£ã®ããã«ããã®æ¸ãè¾¼ã¿ã§ããã(^^;