Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

exceptions  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone plz tell me what exactly is a checked exception and how is it different from an unchecked exception
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at here:
http://www.javapractices.com/Topic129.cjp
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nivi,

Checked exceptions are actually checked by the compiler.These are conditions which need to be dealt with compulsarily by the part of the code implementing these conditions.

For example, if a method is using some File Operation then it needs either to deal with the exception directly or pass these exceptions to the caller method.

Unchecked exceptions are genuine defects or logical errors in the code.They are not checked at compile time but at runtime. eg ArthmeticException,ArrayIndexOutOfBoundsException.

Hope the explaination helps.

Nikhil
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi nivi

in java checked exceptions are exceptions which must be handled by either the method throwing the exception or by its calling method or if the current method has ducked the exception by declaring it then the caller method has to handle(or catch )it.
all exceptions except RuntimeExceptions in java are checked exceptions.
there is no need to declare the unchecked exceptions.but they still need to be handled somewhere down the call stack.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Unchecked exceptions are the subclasses of RuntimeException.

Runtime exceptions represent problems that are the result of a programming problem or the bugs in our program. RuntimeExceptions are exceptions that occur within the JVM during runtime. Thus,the compiler does not require that you catch or specify runtime exceptions (although you can).

Compile time exceptions (Checked Exceptions)are exceptions that occur in code outside of the Java runtime system.The compiler ensures that nonruntime exceptions are caught or specified.

Ashok
 
nivi zal
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot to all of u for helping me understand this!
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!