Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
Jeevanandam Natarajamoorthy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code if from K&B and page no:242.
class TestEx {
public static void main(String args[]){
doStuff();
}
static void doStuff() {
doMoreStuff();
}
static void doMoreStuff(){
int x = 5/0;
}
}
If i compile this code, i am getting compilation error. Bec. the arithmetic divison is hard coded. But the expected ans. is exception. It will happens only if i use the var. like int x = a/b; (a is some val & b is zero).
For such type of questions , what we have to answer.. like compilation error or runtime exception ??!?!.
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Jeevanandam!
What version of JDK are you running?
 
Jeevanandam Natarajamoorthy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK1.3
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey buddy, we're 1.4.x now!
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- this would be a definite runtime exception... even if you *do* have a compiler that can look at it and say, "Oh come ON! This will NEVER work!!" (because of the hard coding).
So whether your compiler catches it is a dependent on your compiler. So if you see something that's hard coded, we do that to make sure that you can see exactly what is there, but I can't think of any area on the exam where you'd have something like this that would be confusing...
Anyway, good question
cheers,
Kathy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic