aspose file tools*
The moose likes Java in General and the fly likes Throwable class in Java - Serializable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Throwable class in Java - Serializable" Watch "Throwable class in Java - Serializable" New topic
Author

Throwable class in Java - Serializable

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 132
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

Joined: Jul 11, 2012
Posts: 8

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

Joined: Mar 05, 2008
Posts: 2969
    
    9
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

Joined: Jul 05, 2012
Posts: 74

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Throwable class in Java - Serializable
 
Similar Threads
why wouldn't all Java classes be serializable
wild cards
how makeChild classes as Non Serializable if parent class is Serializable in java ?
Is Java.lang.Exception is Serializable??
SERIALIZABLE CLASSES