c# - 控制台应用程序中System.Xml的C#错误处理

标签 c# error-handling unhandled-exception

我继承了C#控制台应用程序,并且我不精通编写错误处理。该应用程序每晚运行数月而没有任何问题后,它开始在过去3天每天都引发以下错误:

 Unhandled Exception: System.Xml.XmlException: An error occurred while parsing EntityName. Line 5, position 338.
    at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
    at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
    at System.Xml.XmlTextReaderImpl.FinishPartialValue()
    at System.Xml.XmlTextReaderImpl.get_Value()
    at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
    at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
    at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
    at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
    at System.Xml.Linq.XDocument.Load(String uri)
    at Data.Service.AssignmentService.<HandleMarkupActivityStep>d__10.MoveNext() in C:\Users\default\Source\Workspaces\Data\Data - Transfer\Data.Service\AssignmentService.cs:line 381
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Vital4Data.Service.AssignmentService.<ProcessSingleHtmlSource>d__17.MoveNext() in C:\Users\default\Source\Workspaces\Data\Data - Transfer\Data.Service\AssignmentService.cs:line 948
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
    at System.Threading.ThreadPoolWorkQueue.Dispatch()
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
 Status changed to Failed
 Job failed due to exit code -532462766

在我可以让某人深入应用程序解决问题之前,我只需要应用程序忽略此错误,然后就可以继续进行而不会失败。我将如何在代码中添加错误处理以实现此目的?这是try/catch块的候选人吗?还是try/catch块首先捕获并抛出了该块?我将不胜感激任何指导,因此我可以简单地告诉程序忽略该错误并继续执行。

最佳答案

控制台应用程序通常用于计划的作业。
正如ColinM所说,您应该实现try-catch,但我也建议您记录跟踪以进行进一步分析。

关于c# - 控制台应用程序中System.Xml的C#错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44400124/

相关文章:

c - 我修改的代码中出现未处理的异常

c# - 数据库国际化

c# - 如何将两个 DateTime 与秒进行比较?

c# - View 和 View 模型之间的快捷方式(Visual Studio 2012)

android - Android-Logcat错误

angular - 我无法构建和运行 Angular 应用程序: 'An unhandled exception occurred: NGCC failed.' has anyone got suggestions on how to resolve this?

c# - 递归方法的一部分可能不会在递归中执行

error-handling - Tapestry 5中的类型强制错误处理

php - 我无法将 Sentry 添加到php slim

c# - 尝试读取或写入 protected 内存。这通常表明其他内存已损坏