簡體   English   中英

用戶代碼未處理的異常

[英]Exception Unhandled by User Code

我的應用程序主頁上聲明了一個庫的成員:

private OpticalReaderLib.OpticalReaderTask _task = new OpticalReaderLib.OpticalReaderTask();

在我想在其他時間導航回到此頁面之前,它工作正常。 出現錯誤“ OpticalReaderLib.DLL中發生了'System.Exception'類型的異常,但未在用戶代碼中處理”。

有人知道為什么會這樣嗎?

謝謝。

System.Exception是所有Exception的基類,因此這是一條非常通用的錯誤消息。

您可以嘗試記錄有關在調查過程中引發的異常的更多詳細信息(例如exception.Message或exception.InnerException)。 (通過try-catch語句)。

好像您正在初始化一個字段,此代碼在哪里執行?


由於注釋更新作為發現異常錯誤的臨時解決方案。

    private OpticalReaderLib.OpticalReaderTask _tempTask;
    private OpticalReaderLib.OpticalReaderTask _task
    {
        get
        {
            //code to debug the error that is occuring
            try
            {
                if (_tempTask == null)
                    _tempTask = new OpticalReaderLib.OpticalReaderTask();
                else
                    return _tempTask;
            }
            catch (Exception exception)
            {
                //Log the exception detail here 
            }
        } 
    }
  protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
  {
    if (_task != null) 
    { 
      _task.Completed -= OpticalReaderTask_Completed; 
      _task.Dispose(); 
      _task = null; 
    } 
    base.OnBackKeyPress(e);
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM