2011-05-20 77 views
0

我需要一些調試幫助,因爲我由於某種原因無法使用visual studio的調試器,有關如何使用消息框顯示調試信息的任何想法?使用messagebox顯示調試信息

private void ClickforError(object sender, EventArgs e) 
{ 
    MessageBox.Show(""); 
} 
+1

你需要關於什麼的幫助? – 2011-05-20 10:11:56

+0

編輯了這個問題,對不起,如果起初還不清楚 – redevil 2011-05-20 10:12:59

+1

當然有時候Message Boxes對調試非常有用,但問題是什麼? – 2011-05-20 10:15:12

回答

1

我想我明白。你想要一種自動顯示代碼中給定點的所有變量值的方法。 參見this questionthis question,看看爲什麼這不容易。

this看起來像一個類似的問題和你,建議尋找其他檢測工具,如智能檢查

2

我想你想是這樣的:

private void ClickforError(object sender, EventArgs e) { 
      try { 
       // do something 
      } catch(Exception ex) { 
       MessageBox.Show(ex.Message + "\n" + ex.StackTrace); 
      } 
     } 
+0

笏我應該做的「//做點什麼」? – redevil 2011-05-20 10:25:03

+0

這絕對看起來更接近我的想法,但不幸的是,它不工作,也許是因爲我不知道「//做些什麼」 – redevil 2011-05-20 10:36:08

+0

@redevil你放置你期望拋出異常的代碼。 – Vale 2011-05-20 10:43:48

0

我不知道這是否可以幫助你,但在Windows應用程序,你可以添加事件處理程序捕捉所有線程異常。

Here is the tutorial在那裏我得到的信息

這就是訣竅:

static class Program 
    { 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     static voidMain() 
     { 
      Application.ThreadException += new ThreadExceptionEventHandler(new ThreadExceptionHandler().ApplicationThreadException); 
      Application.Run(new Form1()); 
     } 
     /// <summary> 
     /// Handles any thread exceptions 
     /// </summary> 
     public class ThreadExceptionHandler 
     { 
      public void ApplicationThreadException(object sender, ThreadExceptionEventArgs e) 
      { 
       MessageBox.Show(e.Exception.Message, 「An exception occurred:」, MessageBoxButtons.OK, MessageBoxIcon.Error); 
      } 
     } 
    } 

但這僅顯示錯誤信息...如果你想一些其他的調試信息,我認爲你必須寫一個自定義日誌和編寫所有的信息befor和你想調試的代碼後...

0

好吧,假設你有algorythm由幾個步驟組成。當你可以在「調試它」以這樣的方式

perform step1 
display MessageBox with results of step1 

perform step2 
display MessageBox with results of step2 
. 
. 
. 
perform stepN 
display MessageBox with results of stepN 

當你發現了哪個步驟與錯誤結束,則應該在它的子步驟提示消息框,並檢查每一子步的結果。這種迭代方法會引導您回答問題:「錯誤在哪裏?」