[英]Continue to next blob in the ForEach Block when there is an exception in the Catch block
I have many xmls in Azure Storage container. 我在Azure存储容器中有很多xml。 I wrote code to strip off unnecessary data elements from those xmls.
我编写了从这些xml剥离不必要的数据元素的代码。 To list all the xmls in different folder structures I used
列出我使用的不同文件夹结构中的所有xml
var blobs = container.ListBlobs(prefix: <Root Location of Blobs>, useFlatBlobListing: true);
foreach (CloudBlockBlob blob in blobs)
And to parse the xml I am using Linq. 并解析xml我正在使用Linq。
The problem I am facing is there are few xmls that are missing the proper format or few xmls that doesn't have closing literals. 我面临的问题是,缺少正确格式的xml很少,或者没有闭合文字的xml很少。 I want to catch the exception and skip that xml file from processing and proceed to the next one.
我想捕获异常并从处理中跳过该xml文件,然后继续进行下一个。 How can I do that using the Try catch block ?
如何使用Try catch块来做到这一点?
The exception I get is System.Xml.XmlException
我得到的异常是
System.Xml.XmlException
Try 尝试
foreach (CloudBlockBlob blob in blobs){
bool isError = false;
try
{
// do your code here;
}catch(Exception ex){
isError = true;
}
if(isError) continue;
}
Update: 更新:
void Main()
{
string[] list = new string[]{"bob", "jack", "tom", "sparrow"};
foreach(string li in list){
try{
if(String.Equals(li, "tom")){
throw new Exception("Fault");
}
Debug.WriteLine(li);
}catch(Exception ex){
Debug.WriteLine(ex.Message);
continue;
}
}
}
Prints: 印刷品:
bob
jack
Fault
sparrow
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.