Question: I've a few Classes from a assembly which is .Net 2.0. These Classes are marked with Serializable.

In my project, I use these classes in my Classes, which are marked with DataContract(IsReference=true) and DataMember.

Now I have the problem, with DataContractSerialiser that it serializes the private fields of my .Net 2.0 Classes, which will not work. But when I use XMLSerialiser, I cannot use IsReference, and so I can also not do this.

Is there a easy (simple) Solution for this? Maybe a someone has a own XMLSerializer which supports references?

Here is a bit of my code:

```
[DataContract(IsReference = true)]
public class ConnectionConfig: INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
            PropertyChanged(this, new PropertyChangedEventArgs("ObjectAsString"));
        }
    }

    private PLCConnectionConfiguration _configuration;
    [DataMember]
    public PLCConnectionConfiguration Configuration
    {
        get { return _configuration; }
        set { _configuration = value; NotifyPropertyChanged("Configuration"); }
    }
}

```

where PLCConnectionConfiguration comes from a .NET 2.0 assembly, and is decorated with [Serializeable]

Answer: 
You are right: exception constructor takes the **pointer** to the string, it does not store a copy of string content. That content is stored in local variable

```
   char adieu[128];

```

which goes out of scope upon exit from Foo::bar method. 

The stack contains 'activation records' (also called 'stack frames') for functions which are currently executing. Each function call allocates memory on that stack for all local variables declared in that function (at machine level, this may be implemented as 'push' or any other command that advances stack pointer). Each return from the function - it does not matter if it's a normal return or exit by throwing an exception - frees the memory which was allocated when entering the function (at machine level, this is implemented as 'pop' or 'restore stack pointer to the value it had when entering the function').

So, when the stack is unwound, all 'activation records' in 'function call chain' or 'stack' between the function where exception was thrown and the function where the exception is caught are freed.
First, your exception class should look like this

```
class MyExcept : public std::runtime_error {
    MyExcept(const std::string & message) : std::runtime_error(message) {}
};

```

That is really all that is needed. You can change the base-class to `std::logic_error` if that suits your needs better (see [here](https://stackoverflow.com/questions/2924058/confused-about-stdruntime-error-vs-stdlogic-error) for an explanation of the distinction, and [here](http://www.cplusplus.com/reference/std/stdexcept/) for a list of other predefined exception classes). You can then build the error message using string concatenation:

```
void Foo::bar() {
    int err = SomeAPIRoutine(...);
    if (err != SUCCESS) {
       throw MyExcept("Error: " + LibErrString(err));
   }
   // otherwise...
}

```

[This FAQ](http://www.parashift.com/c++-faq-lite/exceptions.html) contains more useful information about exception handling, especially how to correctly catch exceptions:

```
try {
    // fail here
}
catch (std::exception & e) { // NOTE: catch by reference!!!
}

```

As to your stack question, the current stackframe is unwound, and all objects in it are destroyed in reverse order of their construction. This is done until the exception is caught. This is the reason why [RAII](http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization) works.