• Post Reply Bookmark Topic Watch Topic
  • New Topic

checked or unchecked  RSS feed

 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how compiler generate checked exception.....for every exception there is a object so.jvm created object for that unchecked exception

but for checked exception there is no object then how compiler identify that eception...

thanks in advance
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ritesh raushan wrote:how compiler generate checked exception


It doesn't generate them. I just compiles code for them like any other class. The language spec says that RuntimeException, Error, and their subclasses are unchecked, and everything else is checked, and the compiler and the JVM are written to adhere to that spec.

but for checked exception there is no object


I don't know where you got that idea, but it's not true.
 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Ritesh raushan wrote:how compiler generate checked exception


It doesn't generate them. I just compiles code for them like any other class. The language spec says that RuntimeException, Error, and their subclasses are unchecked, and everything else is checked, and the compiler and the JVM are written to adhere to that spec.

but for checked exception there is no object


I don't know where you got that idea, but it's not true.
......

please give me step by step for compiler to identify checked exception....
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ritesh raushan wrote:
please give me step by step for compiler to identify checked exception....


I don't know what you're asking.



The language spec says that the first one will be checked and that the second one will be unchecked. The people who wrote the compiler know that, because they read the language spec and are writing the compiler to comply with the spec. So in the compiler there's code that says something like:


Anything beyond that is a compiler implementation detail that we don't know or care about.

 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to identify whether a checked exception can be thrown by a bit of code, the compiler is only looking for two things.

1. throw xyz, where xyz is a reference to a XyzException
2. Any call to a method that declares itself as throws XyzException

where XyzException is any checked exception. And it knows whether XyzException is a checked exception because it knows what the inheritance hierarchy is. So if it extends Exception (or a subclass), and doesn't extend RuntimeException (or a subclass) then it's checked.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:So if it extends Exception (or a subclass), and doesn't extend RuntimeException (or a subclass) then it's checked.

Or more generally, if it extends Throwable (directly or indirectly) and doesn't extend either RuntimeException or Error (directly or indirectly), it's checked.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!