• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception Handling

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??!?!.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDK1.3
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey buddy, we're 1.4.x now!
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic