Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Checked and Unchecked exceptions

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checked and Unchecked exceptions how can you tell the difference.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checked exceptions are all exception classes instantiated from the Exception class, or from subclasses of Exception other than RuntimeException and its subclasses.

For checked exceptions, the code in your method must do something for them and you cannot be ignored them when you write your code. The compiler checks each method to be sure that it does.
[ May 05, 2006: Message edited by: wise owen ]
 
Josh Rema
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that, but how can you tell with out memorizing all the exceptions that are subclassed under checked exceptions.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a very good question. I agree with you that you can not tell without memorizing all the exceptions that are subclassed under checked exceptions.
[ May 05, 2006: Message edited by: wise owen ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My approach was to just memorize common unchecked exceptions, like:
  • ArithmeticException
  • ClassCastException
  • ConcurrentModificationException
  • IllegalArgumentException
  • IllegalMonitorStateException
  • IndexOutOfBoundsException
  • NullPointerException
  • NumberFormatException
  •  
    Ranch Hand
    Posts: 77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    java API's naming convention is designed such that you can easily understand the way the exception is going to behave from its name itself.eg:ArrayIndexOutOfBound is this exception not clear from the name itself??? once you understand the exception type and its working you can easily have in mind. other than that i dont think you are explicitly needed to memorise them until it is very hard to understand. and mind that memorizing will not last for longer time... rather understand..
     
    marc weber
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by vignesh hariharan:
    java API's naming convention is designed such that you can easily understand the way the exception is going to behave from its name itself...


    I would be careful, because that approach can be misleading. For example, the following could easily be seen as RuntimeExceptions, although they are actually checked Exceptions:
  • ClassNotFoundException
  • InterruptedException
  • IOException (including MalformedURLException)
  • etc.
  •  
    Josh Rema
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you guys for all the advice. I believe I will look at the most common checked and unchecked exceptions and try to memorize; as well as, have a good understanding as to why they are being thrown. thx again
     
    Ranch Hand
    Posts: 68
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hi friends,
    in the exam it will be mentioned that its a checked or runtime Excepton. i got a question related exception and it was stated that
    Note : all the methods in the IO package throws checked exception , including close();

    so u dont need to memorize for the exam.
    For real time projects, u just complie it. if it says it should be declared, then its a checked. !!!

    Vidhyakar K
     
    Ranch Hand
    Posts: 175
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Grr!!
    I can't believe you said that. If you let the compiler decide how you write your programs you have a lot of learning to do!!!
    Sashi
     
    reply
      Bookmark Topic Watch Topic
    • New Topic