作者Whistler (Bicycle)
看板C_Sharp
标题Re: [问题] try , catch 找系统问题
时间Fri Nov 11 03:57:52 2005
※ 引述《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