Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exceptions  RSS feed

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How could i know which exceptions are checked and which are not???
 
Sheriff
Posts: 9611
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exceptions which inherit from java.lang.RuntimeException or java.lang.Error class are unchecked, all other are checked...
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All non run-time exceptions are checked exceptions.
 
ujjawal rohra
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is there any way so that i can tell which are checked and which are unchecked only by reading their names
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ujjawal rohra wrote:But is there any way so that i can tell which are checked and which are unchecked only by reading their names


Only *magician* can tell that
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so, you gotta check the official documentation for that. But for the exam, there are certain
very common exceptions which are used like NumberFormatException, NullPointerException. Many of the common ones
i guess you can remember are run-time or not.

Best Regards,
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ujjawal rohra wrote:But is there any way so that i can tell which are checked and which are unchecked only by reading their names



There is no such way
 
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:

ujjawal rohra wrote:But is there any way so that i can tell which are checked and which are unchecked only by reading their names


Only *magician* can tell that


Or the original coder
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pushkar Choudhary wrote:

Seetharaman Venkatasamy wrote:

ujjawal rohra wrote:But is there any way so that i can tell which are checked and which are unchecked only by reading their names


Only *magician* can tell that


Or the original coder



or the JavaDocs

hth,
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ujjawal rohra wrote:How could i know which exceptions are checked and which are not???



Most programmers know the difference between checked and unchecked exceptions by:

1. a lot of years of programming experience

2. memorizing the names of a few checked and unchecked exceptions

3. "being the compiler".
For example, if you are the compiler, can you always predict that some code will throw a NullPointerException? No. Therefore, it must be a runtime (a.k.a. unchecked) exception.
 
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ujjawal rohra wrote:How could i know which exceptions are checked and which are not???


this moslty comes with experience. For the exam purpose you need to know the common exceptions related to exam objectives and should be able to identify which are checked and which are not. For example the following are all checked exceptions. You either need to declare using "throws" or handle in a "try" "catch" block.
  • InterruptedException
  • ParseException
  • IOException
  • ClassNotFoundException
  • FileNotFoundException

  • If you don't remember these, and if these comes in an overriding question, you wont be able to answer it correctly!

    the following are unchecked exceptions (or Runtime Exceptions). You don't need to handle or declare these!
  • NullPointerException
  • ArithmeticException
  • IllegalArgumentException
  • IllegalStateException
  • ArithmeticException
  • IllegalMonitorStateException
  • NumberFormatException
  • IllegalThreadStateException


  • good luck
     
    author
    Sheriff
    Posts: 8977
    17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Ujjawal,

    Do you know why they're called 'checked' exceptions? If you get really clear on that question it can help you remember which are which.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!