• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on NotSerializableException

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I noticed that NotSerializableException is not a subclass of RuntimeException, but why is it not being checked during compilation time? Instead, its occuring during runtime?
[ February 15, 2008: Message edited by: Jart Bo ]
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Good question buddy. I searched it a little and found that
java.lang.Object
extended by java.lang.Throwable
extended by java.lang.Exception
extended by java.io.IOException
extended by java.io.ObjectStreamException
------------------extended by java.io.NotSerializableException !!!----------

So that means if we are catching IOException while compilation which we are forced to do while writing code for Serialization , we are automatically catching the NotSerializableException. So it arises only at run time if the code is infact Not Serializable!
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jart Bo:
Hi Ranchers,

I noticed that NotSerializableException is not a subclass of RuntimeException, but why is it not being checked during compilation time? Instead, its occuring during runtime?

[ February 15, 2008: Message edited by: Jart Bo ]



Hi,

can you show an example when that happen ? Could it be that your are catching "IOException" so NotSerializableException is not automatically added by your editor ? It inherits from IOExcetpion...

Regards,
Alex
 
Jart Bo
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Yeah, it looks like I'm getting you're point. I got this from studying the KB Book Chapter 6:



Since the IOException is already handled, then the compiler gets happy but the said exception still persists at runtime.
 
Jart Bo
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And just to add, the compiler forces to handle IOException, not the NotSerializableException..
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jart Bo:

Since the IOException is already handled, then the compiler gets happy but the said exception still persists at runtime.



When you say they happen at runtime.. You mean the error happens at runtime ? That is the case for all exceptions... They are thrown at runtime..

The difference with Checked Exception is that the compiler forces you to handle it. Which you are doing by catching IOException.
Then, in your IOException catch, you print the stackstrace, so the NotSerializableException is displayed...

Your method throws both NotSerializableException and IOException. NotSerializableException IS an IOException, so the editor only adds this one. You can manually add the other one :


And perhaps you could make your Collar Serializable or transient to either allow Serialization or disable it..

Regards,
Alex
 
Jart Bo
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alex!
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic