• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exceptions

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i get a compiler here that try block never throws an ioexception but it were

then there is no error why?
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes because IOException is a checked exception.
you must do such operation into try block which throw ioexception or throw new IOException () explicitly.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IOEXception is a subclass of Exception right....how is exception not a check exception when it includes both checked and unchecked exceptions
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minhaj kaimkhani wrote:yes because IOException is a checked exception.
you must do such operation into try block which throw ioexception or throw new IOException () explicitly.


what Minhaj says is true.

Raju Champaklal wrote: IOEXception is a subclass of Exception right....how is exception not a check exception when it includes both checked and unchecked exceptions

because it can catch a runtime exception also about which compiler doesn't know anything so it will not give any error and hence Exception can never be checked exception.
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the classes those directly extends java.lang.Exception are checked exception for example
java.io.IOException

and the class those indirectly extends are un-checked exception for example

"java.lang.NullPointerException" <= its an unchecked exception

see the difference into hierarchy

java.lang.Object
extended byjava.lang.Throwable
extended byjava.lang.Exception
extended byjava.lang.RuntimeException
extended byjava.lang.NullPointerException
and

java.lang.Object
extended byjava.lang.Throwable
extended byjava.lang.Exception
extended byjava.io.IOException
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There have been recent discussions in the past on this topic like this or this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic