When calling a method using methodInfo.Invoke, if an exception is thrown, it does not propagate to my catch blocks.
object value; try { value = myMethod.Invoke(null, parameters);//program crashes with uncaught exception } catch { throw new Exception("Caught!");//never executed }
A special exception thrown by this method is a KeyNotFoundException, but it does not matter because I understand everything well?
The specific error message I get from Visual Studio is
KeyNotFoundException was unhandled by user code
whereas as usual the message will be
KeyNotFoundException was unhandled
if the call was not a reflected call.
I could just check the method to see if they have a key, and if not returning null, but using exception handling seems preferable. Is there a way to throw exceptions from the call to the reflected method?
Lucina
source share