.net - Unhandled DivideByZero exception from an external DLL - C# -
i have c# (.net 4.0) program, main calling methods external ftp library - dll project references. logic in try-catch block, , catch prints error. exception handler has generic parameter: catch(exception ex)
. ide vs.
sometimes ftp library throws following division 0 exception. problem is not caught in catch block, , program crashes. exceptions originated in wrapper code caught. has idea difference , how exception can caught?
the exception:
description: process terminated due unhandled exception. exception info: system.dividebyzeroexception stack: @ componentpro.io.filesystem+c_ou.c_f2b() @ system.threading.executioncontext.runtrycode(system.object) @ system.runtime.compilerservices.runtimehelpers.executecodewithguaranteedcleanup(trycode, cleanupcode, system.object) @ system.threading.executioncontext.run(system.threading.executioncontext, system.threading.contextcallback, system.object, boolean) @ system.threading.executioncontext.run(system.threading.executioncontext, system.threading.contextcallback, system.object) @ system.threading.threadhelper.threadstart()
there similar problem described here , here explanation. said in 1 of comments ftp server should handle protocol violations without crashing. should pick ftp if can. however, if want keep using dll need handle exception @ app domain level blorgbeard pointed out.
here example of how catch exception using appdomain.unhandledexception event:
using system; using system.security.permissions; public class test { [securitypermission(securityaction.demand, flags = securitypermissionflag.controlappdomain)] public static void example() { appdomain currentdomain = appdomain.currentdomain; currentdomain.unhandledexception += new unhandledexceptioneventhandler(myhandler); try { throw new exception("1"); } catch (exception e) { console.writeline("catch clause caught : " + e.message); } throw new exception("2"); // output: // catch clause caught : 1 // myhandler caught : 2 } static void myhandler(object sender, unhandledexceptioneventargs args) { exception e = (exception)args.exceptionobject; console.writeline("myhandler caught : " + e.message); } public static void main() { example(); } }
Comments
Post a Comment