• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

method overriding with exceptions

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ExceptionInInitializerError is a subclass of Error but compilers accept it.I am wondering why? and error is an exception, isn't it?
 
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both Error and RuntimeException are unchecked exceptions, meaning you can add Runtime Exceptions and Errors to method signatures.
 
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Luanrkiran kumar wrote:
ExceptionInInitializerError is a subclass of Error but compilers accept it.I am wondering why? and error is an exception, isn't it?




All RuntimeException and all errors are unchecheckd exceptions so compiler doesn’t care about unchecked one but do care about checked exceptions .
In this case we are overriding , so overriding always happen in case of instance block not for static and not for private . Now the problem is we are throwing ExceptionInInitializerErrorexceptions Which is belong to static block means if there is error rising in static initializer block or for static variable then this exception rises. That’s why it gives compiler error . I believe so.
 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry regarding compilation issue i was wrong. It will execute succesfully. All i explained is correct. So again as error is unchecked that's why there is no compilation problem because compiler identify only checked Exceptions.
 
Luanrkiran kumar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't get confuse about static blocks I just used it simply the main thing you have to see is that the overriding method violating the rule because it has error which is parent for that exceptioninitilzererror
 
Luanrkiran kumar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you guys didn't understand my question, consider this below example

now see the compiler alerts you because RuntimeException is a subclass of Exception so I was wondering why the compiler didn't alert me in that my first code which i was posted before.
please help because this is my last topic.
 
Luanrkiran kumar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh I think I got it...The Exception itself isn't an unchecked exception because it has IoExeption which is checked exception....
conclusion: my overriding method contains a checked exception right for above code???
 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three types of exception.......
1) partial checked
2) fully checked
3) unchecked

The Exception which have checked and unchecked child classes is called Partially Checked Exception. which is Throwable and Exceptions.

IOException, InteruptedException and SQLException is Fully Checked Exception because it’s all child classes are also checked exception classes.

In Java exceptions under Error and RuntimeException classes are unchecked exceptions, everything else under throwable is checked.

so there is a rule while overriding you cannot broader your exception . It must be the same as parent class or narrower or you can throw any uncheked exception.

so in your second problem you override the exception with broader one which is exception and in parent you choose uncheked exception so it will give compiler error. opposite will work.
 
Luanrkiran kumar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate your valuable feedback!!!
 
Marshal
Posts: 64710
226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vedanshi Priyadarshi wrote:There are three types of exception.......
1) partial checked
2) fully checked
3) unchecked . . . .

Afraid that isn't correct. If you look in the Java® Language Specification (=JLS), you will find that both Exception and Throwable are checked.

That JLS section wrote:The checked exception classes are all exception classes other than the unchecked exception classes.

That means all exceptions which are not unchecked are checked: there is no partially checked category. The special status of RuntimeException and Error is determined by that part of the JLS, rather than Exception and Throwable having a special status themselves.

And yes, it is very confusing to say run‑time exceptions or to call the class RuntimeException, but it is too late to do anything about that now.
 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception said to be fully checked when all it’s child classes are checked one
Example-
IOException
        -FileNotFoundException
        - EOFException etc.
And we say partiallly checked to Exceptions and Throwable because all it’s child classes are not fully checked ( some are checked and some are not checked it contain both) so how we prove the difference between them. There must be some difference.

 
Saloon Keeper
Posts: 10310
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who says that? Do you have sources for that statement? I've never head the term "partially checked exceptions" before.
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I've never head the term "partially checked exceptions" before.



Me neither. But it's not a very useful category since it only includes Throwable and Exception, and it isn't possible to create other classes in the category.
 
Campbell Ritchie
Marshal
Posts: 64710
226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said earlier, it is RuntimeException and Error that have the special status as unchecked exceptions.
 
Bartender
Posts: 2302
96
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quoting from JLS:

JLS wrote:The unchecked exception classes are the run-time exception classes and the error classes.

The checked exception classes are all exception classes other than the unchecked exception classes. That is, the checked exception classes are Throwable and all its subclasses other than RuntimeException and its subclasses and Error and its subclasses.




My Understanding :
 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://www.quora.com/What-is-a-%E2%80%98partially-checked-exception%E2%80%99-in-Java    here is the link where i found about this and one of the online tutorial too.


 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
 
Luanrkiran kumar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the link if correct, because for me it didn't worked.
 
Luanrkiran kumar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it's a third party website so we can't relay on them however I understood the concept and lol this post gathered so many people because exceptions is one hell of a topic...
After reading all your replies now I really got deep understanding of exceptions thank you everyone for your replies and I think we can end this topic...
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first link would work with some editing, but the second link does work and contains the same text as the first one would, if you could get to it.

But I still think those names are silly. All "fully checked exceptions" are checked exceptions, and all "partially checked exceptions" are checked exceptions. That could be confusing, and "partially mean in parts" doesn't dispel the confusion at all. It just leads to the question "Okay then, what's an "in parts checked exception?"

The only difference between the two kinds of checked exceptions is that one type has subclasses which are unchecked exceptions and the other type doesn't. In my opinion it's better to understand the diagram which Salvin posted -- it's quite straightforward and doesn't require any confusing terminology to explain it.
 
Shweta Priyadarshi
Ranch Hand
Posts: 42
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to all for all this trouble.

But i always trying to help people if really i can with all the knowledge i have . I am the beginner . I apology again if i have troubled you all.
Yes exception is tough
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vedanshi Priyadarshi wrote:Sorry to all for all this trouble.



It's not trouble at all. Discussions are always good here, with different ideas being posted you can choose the ones you like and disregard the others. More ideas are better than less.

Yes exception is tough

Yup, the original Java engineers didn't make them easy to understand! I often wonder if they could have created a design which was easier to understand -- but it's not like they were a bunch of beginners. They were engineers with a good deal of experience in language design. So I shouldn't complain unless I can come up with a better design, one which actually works. Which I haven't got around to doing just yet...
 
Campbell Ritchie
Marshal
Posts: 64710
226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shweta Priyadarshi wrote:http://ktutorials.com/java/fully-checked-vs-partially-checked-exceptions-java/

You mean somebody had the bright idea of creating a new category and writing a tutorial about it? I still don't believe that Throwable is checked in part, as that title would suggest.

I had a look at a few pages in that tutorial and I think it is poor quality.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!