我有一个循环(见下文)。如果我输入任何 catch 块,我想结束我正在循环的项目的循环(我有一个文件路径数组)。
说项目是 file = "C:\test.txt"
循环这个文件(C:\test.txt)时,如果出现问题,我想停止这个文件的循环,但继续 foreach 数组 finalFiles 中的其他文件。
这可能吗?
foreach (string file in finalFiles)
{
if (file.Contains(".tiff") == true)
{
PolicyNumber = Path.GetFileName(file).Split('_')[0];
basePolicyNumber = PolicyNumber.Remove(PolicyNumber.Length - 2);
basePolicyNumber = basePolicyNumber + "00";
finalPolicyName = Path.GetFileName(file);
try
{
PolicyUUID = Transporter.GetPolicyUUID(AppVars.pxCentralRootURL, basePolicyNumber);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error getting UUID from policy online!", MessageBoxButtons.OK, MessageBoxIcon.Error);
uploadToPxCentralWorker.ReportProgress(0);
}
ixLibrarySourceFileURL = AppVars.ixLibraryPolicyAttachmentsURL + finalPolicyName;
try
{
Transporter.UploadFileToixLibrary(AppVars.ixLibraryPolicyAttachmentsURL, file);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
uploadToPxCentralWorker.ReportProgress(0);
error = 1;
}
}