wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Jeevanandam Natarajamoorthy
Greenhorn

Joined: Oct 22, 2003
Posts: 3
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

Joined: Aug 25, 2003
Posts: 504
Welcome to JavaRanch, Jeevanandam!
What version of JDK are you running?
Jeevanandam Natarajamoorthy
Greenhorn

Joined: Oct 22, 2003
Posts: 3
JDK1.3
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Hey buddy, we're 1.4.x now!
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
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


Co-Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596007124/ref=jranch-20" target="_blank" rel="nofollow">"Head First Design Patterns"</a><br /> <br />Just a Jini girl living in a J2EE world.
 
 
subject: Exception Handling