• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How RuntimeException is unchecked while Exception is checked?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All CodeRanch Members,
This is my first post and i hope its not a stupid/repeated question.

According to API RuntimeException extends Exception. When we throw new RuntimeException(); we need not declare or handle it but when we throw new Exception(); we have to handle or declare it.
How is it possible because when we create our custom exception(i.e by extending Exception) it also becomes checked but why is RuntimeException unchecked even after extending Exception?
Is RuntimeException specially handled by JVM or there is some other reason?

Regards,
Vivek
 
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vivek,

Welcome to java ranch.

I think the compiler treats the exceptions differently when they extend Exception directly. As the checked exceptions are meant to be handled you will be forced to catch them or let the caller method handle them. In case of run time exceptions then compiler don't enforce any rule because they are not meant to be handled (probably user may not be able to do anything if they occur, the better way would be make sure run time exceptions may not occur).
 
Vivek Hari Narayanan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ramesh maredu wrote:Hi Vivek,

Welcome to java ranch.

I think the compiler treats the exceptions differently when they extend Exception directly. As the checked exceptions are meant to be handled you will be forced to catch them or let the caller method handle them. In case of run time exceptions then compiler don't enforce any rule because they are not meant to be handled (probably user may not be able to do anything if they occur, the better way would be make sure run time exceptions may not occur).



Hi Ramesh,
Thanks a lot i finally got my doubts cleared
 
You can't expect to wield supreme executive power just because
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic