Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Exceptions

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<if catch throws a new exception, not mentioned with any throws clause, then it will not be handled. The>
reason mainly being that
1)it was not declared in throws
2)there is no mention in try block to handle it.
Plz confirm!

public class divby0{
public void div() throws ArithmeticException{
int n1= 2;
int n2= 0;
try{
System.out.println(n1/n2);
}
catch ( ArithmeticException e)
{
System.out.println("i will catch this exception");throw new RuntimeException ();
}
finally{
System.out.println("finally...going out");
}
System.out.println("over to roger");
}
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you need a nested try-catch, in Outer try block you need to handle the exception thrown by the statement
throw new RuntimeException ();
Hope this helps.
Thanks
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic