• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime exceptions??

 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

my doubt is can the Runtime exceptions be caught ??
 
Ashwin Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any class that extends the "Throwable" class can be caught using the try/catch block. (Includes both Exceptions and Errors)

Since "RuntimeException" indirectly extends this class, it can very well be caught. I dont see any issues.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Have a look at the code ..and try to execute it


Hope you can figure it out...
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same question was asked last week. As said in the previous post .
Any class that's an instance of java.lang.Throwable can be caught.
 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes kumar i have executed the ur code ..

coz of the last Runtime exception it is giving me the fatal exception ...
which was not put in the try catch block ...

that means u can catch the runtime exceptions also...

thanks
sri
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Srikkanth..

What i wanted to show you was that we can catch Runtimeexceptions...(first exception..in try block)

or if you dont..the runtime environment handles it..(second one without try-catch block)

Hope you doubt is cleared..

Also look at srinivas's post..he has rightly pointed out..


Any class that's an instance of java.lang.Throwable can be caught.


Checked exceptions..you have to catch....in try catch block

Unchecked ...you can catch if you want..or you need not catch it..Its your decision..

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic