VistaDB 6
VistaDB / Developer's Guide / How To Perform Common Tasks / Handle SQL and VistaDB Exceptions / Serialization of Exceptions
In This Topic
Serialization of Exceptions
In This Topic

VistaDB supports the ability to serialize VistaDB exceptions.

There is a sample application included (called SerializeExceptions) that demonstrates how to do this from code.

To serialize an exception using a SOAP formatter looks like this:

Serializing a VistaDB Exception for SOAP
Copy Code
VistaDBException deserializedExceptionSoap;

// This FileStream is used for the serialization as a SOAP object // You can open this soap file and read it as an XML document
using (FileStream streamSOAP = new FileStream("NewException.soap", FileMode.Create))
{
    // Serialize the exception to the soap file
    SoapFormatter formatterSOAP = new SoapFormatter(null, new StreamingContext(StreamingContextStates.File));
    formatterSOAP.Serialize(streamSOAP, ex);
    // Rewind the streamSOAP and deserialize the exception.
    streamSOAP.Position = 0;
    deserializedExceptionSoap = (VistaDBException)formatterSOAP.Deserialize(streamSOAP);
}
// Throw the deserialized exception again.
throw deserializedExceptionSoap; 

Same example using a BinaryFormatter to put the data to disk.

Serializing a VistaDB Exception for Disk
Copy Code
VistaDBException deserializedExceptionSoap;
// Do the same thing with a binary formatter
using (FileStream streamBinary = new FileStream("NewException.bin", FileMode.Create))
{
    BinaryFormatter formatBinary = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.File));
    formatBinary.Serialize(streamBinary, ex);
    streamBinary.Position = 0;
    VistaDBException deserializedExceptionBinary = (VistaDBException)formatBinary.Deserialize(streamBinary);

    Console.WriteLine("Serialized the exception, and then deserialized the resulting stream into a new VistaDBException. ");
}

// Throw the deserialized exception again.
throw deserializedExceptionBinary; 
See Also