• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic