c# - 如何处理在外部 dll 上抛出的异常?

标签 c# visual-studio-2010 visual-studio exception exception-handling

我开发了一个使用外部 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/

相关文章:

c# - 仅在 IDE 之外的 Release模式下 x64 .NET 4.0 应用程序崩溃

mysql - ComboBox 是数据绑定(bind)的,我想在文本框中显示数据

MySQL 数据源向导不适用于 Visual Studio 2017

visual-studio - 如何在 VS 项目中禁用 clang-cl 特定警告

c# - 从文件名获取日期时间

c# - 选择其中列 1 = 1 且列 2 = MAX(列 2)

c# - Xamarin 表单选择器级联

c# - 如何确定不同范围内两个变量的引用相等性?

c# - 如何使用 C# 和 twilio API 发送短信

c# - 如何在 Internet Explorer 中显示来自 BHO 的警告或栏?