Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can anyone provide an example which explains the difference between a compile time error and a runtime error?
Posted
Updated 14-Nov-11 20:41pm
v2
Comments
André Kraak 15-Nov-11 2:41am    
DO NOT SHOUT when asking a question. When you use all capital letters it is seen as shouting on the Internet and considered rude. Next time when posting a question please use proper capitalization.
[no name] 15-Nov-11 2:54am    
thanq for suggestins

A compile time error is one which is detected before teh program starts running:
C#
int i = 17;
if (i - 5)
   {
   }
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:
C#
int i = 17;
int[] ar = new int[3];
ar[i] = 42;
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.
 
Share this answer
 
Comments
Sandesh M Patil 1-May-12 2:22am    
Good answer
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
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900