Re: [問題] try , catch 找系統問題

看板C_Sharp (C#)作者 (Bicycle)時間20年前 (2005/11/11 03:48), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《kingtw1978 (King)》之銘言: : 用 try 和 catch 找系統bug問題 : (1)如果我現在輸入的資料格式是錯誤的,就顯示 Bad input! : 我在 catch 那邊寫 : catch(這邊要怎麼寫?) : { : Console.WriteLine("Bad input!"); : } : 這樣寫 show 不出來 Bad input! 資訊.... @@ : (2)如果只要顯示系統錯誤訊息,下面這樣就應該可以了吧 : catch(System.Exception error) : { : Console.WriteLine(error.Message); : } : PS:對於 catch() 裡面的寫法還不是很了解 try/catch不是讓你debug用的, 如果你真的有bug, 你應該讓他成為unhandled exception然後crash into debugger 然後你就可以在debugger裡面檢查你的exception object 即使你的exception最後會被handle, 你也可以用VS debugger的filter exception 或是CDB/Windbg的 "sxe clr"指令 來讓你的程式break into debugger catch exception是個很貴的事情 (stack walk...) 你不該利用exception來report input error 這也是為什麼很多在Everett有Parse()的class, 在Whidbey都加上TryParse() -- There are only 10 types of people in the world: Those who understand binary, and those who don't. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 131.107.0.88
文章代碼(AID): #13SwGPgl (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #13SwGPgl (C_Sharp)