For this method, XmlSerializer.Deserialize, what kinds of exception may be thrown? XmlException? InvalidOperationException? I did not find any exception description information from this method. My question is what kinds of exception could be thrown from this method?
http://msdn.microsoft.com/en-us/library/dsh84875.aspx
I am using VSTS2008 + C# + .Net.
thanks in advance,
George
Looks like primarily
InvalidOperationException.If you go through the documentation for each of the overloads, it will give you more details. For example, see
XmlSerializer.Deserialize Method (XmlReader)The
InvalidOperationExceptionwill contain more details about the specific error in itsInnerExceptionproperty.Edit:
The
XmlSerializer.Deserialize Method (XmlSerializationReader)can throw aNotImplementedException, but it is an internal API and is not meant to be used by your code, so don’t worry about it.Edit 2:
This code:
throws:
So it really looks like the framework will always throw an
InvalidOperationException.Really, unless you’re worried about mistakenly catching exceptions like
ThreadAbortException, you are probably safest catching all exceptions…Edit 3:
Using Reflector: The
Deserialize(stream)method reads the stream using anXmlTextReaderand calls theXmlSerializer.Deserialize Method (XmlReader, String). That method throws anInvalidOperationExceptionon error (according to the docs).Edit 4:
Deserialize(stream)can also throw aNullReferenceExceptionifstreamis null, because it calls theXmlTextReader(Stream)constructor.