Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, July 5, 2011 5:27 PM
There is not try .. catch block for a function defined in the dll. I am calling this function in my application. How can I catch if an exception occured in this function ?
All replies (7)
Wednesday, July 6, 2011 2:38 PM âś…Answered
There are a couple of ways to solve this issue in this link Need to do ctrl+F5 instead of F5 so that VS will not stop at the point where exception occured http://stackoverflow.com/questions/4117228/c-reflection-methodinfo-invoke-block-exceptions-from-inside-the-method
Tuesday, July 5, 2011 5:31 PM
You should be able to put your function call into its own try/catch block.
Matt
Tuesday, July 5, 2011 5:57 PM
try{
var someObjinOtherDll = new SomeObject();
someobjectinOtherDll.DoWork();
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
Tuesday, July 5, 2011 9:51 PM
I am using the try ..catch as shown above but the exception occured in the function (in dll) is not caught by the catch block.
Tuesday, July 5, 2011 10:17 PM
How do you know that an exception is being thrown (and not handled) by the dll?
Show us your code
Wednesday, July 6, 2011 9:41 AM
if u r calling dll. u can throw exception from method itself no need to write try catch.
Wednesday, July 6, 2011 2:04 PM
I am using reflection to call the method. Works fine when I created an object for the class in the dll and called this function but doesn't work when I invoke the method using reflection
try
{
result = sm.Invoke(obj, parameters)
}
catch (Exception ex)
{
// need to catch the exception
}
Function that generates an exception in dll
public int GenerateException()
{
int i = 0;
int j = 1;
return (j / i); //This will throw DividebyZero exception
}