• 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

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I have placed pretty the same two code.
What is the difference. If I un-comment "// throw new SimpleExceptio", I
have problem in compiling the code. Please can you explain, why do I have compilation problem ?

thanks
siva



[CODE:1] class SimpleException extends Exception {}

public class SimpleExceptionDemo {

public void f() throws SimpleException {
System.out.println( "Throwing SimpleException from f()");
throw new SimpleException ();
}


public static void main(String[] args) {
SimpleExceptionDemo sed = new SimpleExceptionDemo();


try {


// throw new SimpleException ();

if (sed != null ) {
throw new SimpleException (); }

System.err.println("Caught it-3!");

} catch(SimpleException e) {
System.err.println("Caught it-main()!");
}



}
} ///:~
[/CODE]




[CODE:2] class SimpleException extends Exception {}

public class SimpleExceptionDemo {

public void f() throws SimpleException {
System.out.println( "Throwing SimpleException from f()");
throw new SimpleException ();
}


public static void main(String[] args) {
SimpleExceptionDemo sed = new SimpleExceptionDemo();


try {


throw new SimpleException ();

if (sed != null ) {
throw new SimpleException (); }

System.err.println("Caught it-3!");

} catch(SimpleException e) {
System.err.println("Caught it-main()!");
}



}
} ///:~
[/CODE]
[ August 01, 2004: Message edited by: Siva kandasamy ]
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is fundamentally no difference if you un-comment //throw new SimpleException(); All you do is force it through the if statement, upon which it will throw the same exact exception.

I just compiled your code fine. If you are having problems, check the file name - be sure that it is saved under SimpleExceptionDemo.java, which is the main class.
 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Did you compile the code:2. ie. code I placed below in my posting.
Here is the error message:

~/rd/java/error % javac "SimpleExceptionDemo.java"
SimpleExceptionDemo.java:20: unreachable statement
if (sed != null ) {
^
1 error
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Siva,
 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect. Thank You.
-siva
reply
    Bookmark Topic Watch Topic
  • New Topic