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

java.lang.Exception is checked or not?

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have on query regarding exceptions, basically people consider java.lang.Exception as a checked exception. If RuntimeException itself is a subclass of Exception,then why Exception is checked and RuntimeException is unchecked? Please provide the explanation and if java.lang.Exception is a checked exception then why we don't need to handle the following at compile time??

public static void main(String...args) throws Exception{
//do some stuff........O'reilly
}
 
Marshal
Posts: 79233
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have got SCJP you must have forgotten what you learned for the exam.

The details are all in the Java Tutorials.
 
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A RuntimeException class represents exceptions that occur within the Java virtual machine (during runtime). An example of a runtime exception is NullPointerException. The cost of checking for the runtime exception often outweighs the benefit of catching it. Attempting to catch or specify all of them all the time would make your code unreadable and unmaintainable. The compiler allows runtime exceptions to go uncaught and unspecified. If you like, you can catch these exceptions just like other exceptions. However, you do not have to declare it in your �throws" clause or catch it in your catch clause. In addition, you can create your own RuntimeException subclasses and this approach is probably preferred at times because checked exceptions can complicate method signatures and can be difficult to follow.
 
pawan chopra
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell Ritchie
If you have got SCJP you must have forgotten what you learned for the exam.


Well I know Its really bad that I forgot this if it was written anywhere in kathy seira's book.I didnt see this in that book or may be I didnt read it properly(Generally the worst part is my aim was to just clear the ceritification). Anyways thanks for reminding me that I should have knowledge of these things because I am an SCJP .
 
Campbell Ritchie
Marshal
Posts: 79233
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyway, have you found out from the link I gave you whether java.lang.Exception is checked or not? The API for Exception doesn't tell you.
 
Campbell Ritchie
Marshal
Posts: 79233
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And sorry for being rude about the exam.
 
pawan chopra
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its all right , there should be someone for people like me to realize them the truth!!

Anyways, I found this from that tutorial:

All exceptions are checked exceptions, except for those indicated by Error, RuntimeException, and their subclasses.


And the class java.lang.Exception comes under exceptions category in API!!

Please explain what is true? Is it checked?
 
Campbell Ritchie
Marshal
Posts: 79233
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java Language Specification doesn't tell you a lot more.
Throwable: checked.
Error: unchecked.
All sorts of error including ThreadDeath and AssertionError: unchecked.
Exception: checked.
RuntimeException: it says in the API link that is is unchecked and gives a list of subclasses.
Subclasses of Exception as on its API page: checked, except for RuntimeException.
Your own Exceptions: If they have RuntimeException as a superclass, directly or indirectly: unchecked, otherwise unchecked.
[ November 03, 2008: Message edited by: Campbell Ritchie ]
 
pawan chopra
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the confirmation!!
 
Campbell Ritchie
Marshal
Posts: 79233
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome and sorry for being rude earlier.
 
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic