如何使用C#解决未处理的异常 [英] How to solve unhandled exception using C#

查看:461
本文介绍了如何使用C#解决未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我经常使用try catch块来捕获错误,但我不知道为什么我的应用程序因显示错误而崩溃如下。



应用程序遇到问题需要关闭



此外我的应用程序包含许多表单,包括Program.cs,它是起始类。然后另一个表格(FrmMain)从Program.cs启动。



FrmMain打开订单详情并打开多种表格。



那么如何找到这些类型错误的根本原因。

Hi,
I often use try catch block to catch errors but I don't know why my application crashes by displaying errors as follows.

Application has encountered a problem and needs to close

Moreover My application consists of many forms including Program.cs which is the starting class. Then Another Form (FrmMain) gets launched from Program.cs.

FrmMain opens order details and opens many forms.

So how to find the root cause for these type of errors.

推荐答案

做我们做的。为未处理的异常编写处理程序,并将异常和跟踪注销写入文件或通过电子邮件发送给自己。



这将为您提供例外,模块名称,它出现的行号。
Do what we did. Write a handler for unhandled exceptions and write the exception and trace log out to either a file or email it to yourself.

That will give you the exception, module name, and line number where it occurred.


这些错误没有一个根本原因 - 除了编程不好 - 当出现问题时会发生异常,这意味着某些操作无法完成。 />


该操作可以像除以零或空引用一样简单 - 或者它可能深埋在您的代码要求的一些SQL中要执行的SQL Server。



我们说不出来。您必须单独查看每个,并找出它是什么样的异常,然后开始查看您的代码以找出原因。


对不起 - 但是我们不能为你做那件事。
There is no one root cause for these errors - except poor programming - exception happen when there is a problem which means that some operation cannot be completed.

That operation could be as simple as a "divide by zero", or a "null reference" - or it could be buried deep in a bit of SQL that your code asks SQL Server to execute.

We can't tell. You will have to look at each one individually, and work out what kind of exception it is, and then start looking at your code to work out why.

Sorry - but we can't do that for you.


这篇关于如何使用C#解决未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆