显示目录

加入书签

主页: AutoCAD .NET 开发人员手册
处理错误

处理错误

捕捉运行时错误
There are three different
types of errors you can encounter in your applications: compile-time
errors, runtime errors, and logic errors.
可能在应用程序中遇到的错误有三种不同类型:编译时错误、运行时错误和逻辑错误。
- Compile-time errors occur during the construction
of your application. These errors consist mostly of syntax mistakes,
and variable scope and data type problems. In C# and VB.NET, these
types of errors are caught by the development environment. When
you enter an incorrect line of code, the line is underlined and
the problem with the code line is displayed in a tooltip when the
cursor is positioned over the underlined text. Compile-time errors
must be corrected before the .NET assembly for the application can
be built.
- 编译时错误发生在构造应用程序的过程中。这些错误大部分是语法错误、变量作用域问题或数据类型问题。在 C# 和 VB.NET 中,这些错误类型会被开发环境捕获。当用户输入了错误的代码行,该代码行会被加下划线,当光标定位在它上面时代码行的问题将会显示在一个工具提示中。在编译 .NET 程序集前必须更正编译时错误。
- Runtime
errors are a little more difficult to find and correct. They occur during
the execution of your code, and often involve information provided
by the user or files that are expected to be present. For example,
if your application requires the user to enter the name of a drawing
and the user enters a name for a drawing that does not exist, a
runtime error occurs. To handle runtime errors effectively, you
must predict what kinds of problems could happen, trap them, and
then write code to handle these situations.
- 运行时错误比较难找出和更正。此类错误发生在代码执行期间,通常涉及到从用户或预先保存的信息。例如,如果应用程序需要用户输入图形的名称,而用户输入了不存在的图形的名称,则将发生运行时错误。要有效地处理运行时错误,用户必须预测可能会发生哪些种类的问题,接着捕获这些问题,然后编写代码来处理这些情况。
- Logic
errors are the most difficult to find and correct. Symptoms of logic errors
include situations in which there are no compile-time errors and
no runtime errors, but the outcome of your program is still incorrect.
This is what programmers refer to as a defect or bug. A defect can
be very easy or difficult to track down.
- 逻辑错误最难找出和更正。逻辑错误的症状是不包含编译时错误和运行时错误,但程序的结果仍然不正确。这就是程序员通常所说的缺陷或错误,捕捉到这种程序错误可能很容易也可能很难。
Information on finding
and correcting errors can be found in the documentation for your
development environment. AutoCAD-specific errors fall into the
runtime error category, so these types of errors are covered in
this documentation.
关于查找和更正这三种错误的信息,请参见开发环境的文档。AutoCAD 特有的错误属于运行时错误,因此本文档涵盖了大部分此类错误