This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exception" Watch "exception" New topic
Author

exception

Beny Na
Ranch Hand

Joined: May 26, 2004
Posts: 159
hi

why we can;t throw more than one excption in a try block as shown in below code.

public int method6() {

//throw new RuntimeException();
try{
throw new ArithmeticException();
throw new RuntimeException();
}
catch(RuntimeException re){
}
return 0;
}

but if we provide in the if else code then it will compiled
public int method6() throws Exception {

try{
int i = 1;
if (i==1){
throw new ArithmeticException(); }
else {

throw new RuntimeException();}
}
catch(RuntimeException re){
}
return 0;

}
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
In your first example the second throw clause will never be reached, so the compiler will complain about it being unreachable.

However, in the second example, there is a chance of either one of the throw clauses will execute (depends on the result of the expression in the if-stat), so the compiler won�t complain about it.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Beny Na
Ranch Hand

Joined: May 26, 2004
Posts: 159
thanks a lot for your reply, it is make sense for me now.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: exception
 
jQuery in Action, 3rd edition