编译时间和运行时错误有什么区别 [英] What is the difference between compile time and runtime error

查看:83
本文介绍了编译时间和运行时错误有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提供一个解释编译时错误和运行时错误之间差异的示例吗?

Can anyone provide an example which explains the difference between a compile time error and a runtime error?

推荐答案

编译时错误是在teh之前检测到的一个错误程序开始运行:
A compile time error is one which is detected before teh program starts running:
int i = 17;
if (i - 5)
   {
   }

会导致编译错误,因为"i-5"不是布尔值-它是整数-并且if条件必须在C#中为bool

运行时错误是仅在程序运行时才检测到的错误:

will cause a compilation error, because "i - 5" is not a boolean vlaue - it is integer - and if conditions must be bool in C#

A run time error is one that is only detected when the program runs:

int i = 17;
int[] ar = new int[3];
ar[i] = 42;

将导致运行时错误,因为用作数组索引的i的值超出了数组的范围.

运行时错误可以用try...catch块捕获,而编译时错误则不能.

will cause a run time error, because the value of i being used as an array index is outside the bounds of the array.

Run time errors can be trapped with a try...catch block, compile time errors cannot.


是的,可以肯定,有人可以.我敢肯定,大多数成员都可以做到这一点.
那是你想知道的吗?

—SA
Yes, sure, someone can; most of the members would be able to do that, I''m sure.
Is that what you wanted to know?

—SA


第一印象中,我认为您是编程的初学者,但查看您的个人资料似乎并不正确.

我认为您应该回到基础知识.

http://en.wikipedia.org/wiki/Compiler
On the first impression, I thought your are very beginner to Programming, but looking at your profile it does not seems to be true.

I think you should go back to basics.

http://en.wikipedia.org/wiki/Compiler


这篇关于编译时间和运行时错误有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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