我开发了一个使用外部 dll 作为 FTPServer 的项目,我在我的项目上创建了这样的 FTP 服务器:
private ClsFTPServer _ClsFTPServer;<br/>
_ClsFTPServer = new ClsFTPServer(FTPUserName, FTPPassword, FTPPath);
上面的代码创建了一个 FTP 服务器类的实例,该类在它的构造函数上启动了 FTPserver,它作为一个模块独立工作,当客户端正确发送他们的请求时,但是当一个不正确的请求到达 FTP 服务器时,它会抛出一个异常并导致我的应用程序崩溃。
如何处理外部 dll 抛出的异常以防止我的应用程序崩溃?
最佳答案
我最近回答了一个可能有用的类似(ish)问题 - Catch completely unexpected error
编辑。我必须同意 Hans 上面的评论 - 可能是寻找另一个 FTP 服务器的想法。
为了完整起见,这里是应用程序域/线程异常设置,来自 - http://msdn.microsoft.com/en-GB/library/system.windows.forms.application.threadexception.aspx
Application.ThreadException += new ThreadExceptionEventHandler (ErrorHandlerForm.Form1_UIThreadException);
// Set the unhandled exception mode to force all Windows Forms errors to go through
// our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
关于c# - 如何处理在外部 dll 上抛出的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14976959/