• 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 q

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;
public class Sarim {
public static void main(String arg[]) {
doThis();

}

public static void doThis() {
try {
throw new ArithmeticException();
System.out.println("this is mystery");
}
catch(ArithmeticException ae) {
System.out.println("since i caught");
}
System.out.println("it should now run");


}
}
// I created this code, how come IT IS GIVING ME A COMPILER ERROR SAYING THAT THE PRINTLN STATEMENT IS NOT REACHED, IT IS REFERRING TO THE ONE SAYING "..mystery.." ?
since there is arrangement for catching this, shouldnt the code progress afterwards, printing the other stuff atleast ??
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sarim the reason for this error is that when it comes accross the throw line then it directly jump to the catch statement and the println line is never executed, so it is giving u this error. Give the statement of throw in if block, and then try the code it will not give u this error any more.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic