eocron
eocron

Reputation: 7526

Attach stack trace to exception?

As you all know exceptions is not serializable in general and after catching some very strange bugs in various serializers upon serialization/deserialization of different .NET Exceptions, I came up with simple DTO for trasport level:

[DataContract]
public class Error
{
    [DataMember]
    public string Message {get;set;}
    [DataMember]
    public string StackTrace {get;set;}
    //all Exception fields here
}

I can successfuly transform Exception to Error class, but how to do the opposite? I mean, I want to throw it after actual transportation, with valid remote stack trace and everything as it was before transportation... One way is to use Reflection, but, duh, it is awful and looks unhealthy.

Upvotes: 1

Views: 599

Answers (1)

Chaturvedi Dewashish
Chaturvedi Dewashish

Reputation: 1469

Well I don't fully understood the requirement for doing this but in transport level communication there are always provision for error message/code passing for example WCF has fault-contract you can check. I have found an answer at Serializable Exception which might be suitable for your need. It has three ways of implementation and good code as well.

Upvotes: 2

Related Questions