• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Throwable class in Java - Serializable

 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am just curious to know why Java has made the Throwable class is serializable.

Please share your inputs on the same.

Thanks.
 
Wilhelm Vogt
Greenhorn
Posts: 10
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vaibhav,

I don't know what the thoughts and design choices of the original developers were - but what happens, if there is a serializable class with a method that throws any exception (which is not serializable)?

Regards
Wilhelm
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wilhelm Vogt wrote:what happens, if there is a serializable class with a method that throws any exception (which is not serializable)?

That's not possible. All exceptions are serializable, because they all extend Throwable, which implements Serializable.

Vaibhav G Garg wrote:I am just curious to know why Java has made the Throwable class is serializable.

Well, why not? I'm guessing they thought it would be useful. You often may have a remove client communicating with another machine somewhere via RMI or JMS or a web service or whatever - and if something goes wrong, a Throwable is a common way to transmit info on what the problem was. It wasn't difficult for them to say that any Throwable could be serialized, if you want to. It's just a collection of data about what the program was doing when a problem occurred.
 
Shivom Shukla
Ranch Hand
Posts: 77
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You often may have a remove client communicating with another machine somewhere via RMI or JMS or a web service or whatever - and if something goes wrong, a Throwable is a common way to transmit info on what the problem was.


I agree with Mike, Since we use serialization so that the state of an object is persisted across different JVMs, The problem occurring at one instance should be conveyed as it is to the developer so as to be dealt with. We should think what would happen if it was not serialized? I suppose in case of multiple errors the root cause might get lost(overridden).

Thanks,
Shivom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic