有什么方法可以删除 try-catch 并使用 if 进行相同的工作???
try
{
StorageFile sessionFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(GUID, CreationCollisionOption.OpenIfExists);
if (sessionFile == null)
return Guid.Empty;
using (IInputStream sessionInputStream = await sessionFile.OpenReadAsync())
{
var sessionSerializer = new DataContractSerializer(typeof(Guid));
return (Guid)sessionSerializer.ReadObject(sessionInputStream.AsStreamForRead());
}
}
catch (System.Xml.XmlException e)
{
return Guid.Empty;
}
如果文件不是 XML 格式,我想我会得到异常,或者?