• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

checked or unchecked

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Master Rancher
Posts: 4271
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yeah, but is it art? What do you think tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic