Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compile time and run time error

 
Venu Chakravorty
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are the cases when one is supposed to expect:
1. compile time error
2. run time error
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
venu chakravorty wrote:1. compile time error

Compiler can catch it. mostly related to syntax validation
venu chakravorty wrote:2. run time error

Compiler cant catch it . mostly related to logic of your program
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:
Compiler can catch it. mostly related to syntax validation

Some more examples might be

Typechecking errors
(Rarely) compiler crashes

seetharaman venkatasamy wrote:
Compiler cant catch it . mostly related to logic of your program

Some examples are

Division by zero
Deferencing a null pointer
Running out of memory

 
Kartik Tal
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile time error
--------------------------
string s=null;
This will be compile time error because "string" should be of "String"


Run time error
--------------------
ArrayList arr= new ArrayList();
arr.add("1');
arr.add("2');

System.out.println(arr.get(3));

This will be of run time error as arr is having size of 2 only but you are accessing 3rd one.
 
Raphael Huerta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile time errors happens when you attemp to compile your code and the compiler find errors such as undefined variables, missing parenthesis, accessing variables out of scoped or something like that.

Run time errors happens when your program is running and an unchecked exception is thrown such as NullPointerException or ArithmeticException.
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The really nasty runtime errors occur when the program runs happily and produces the wrong result
 
Venu Chakravorty
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everyone.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic