【发布时间】:2009-10-12 12:04:01
【问题描述】:
最近我参加了一个采访。给了我一个代码 sn-p。我知道,面试官是从 albhari 的线程样本中获取的。
public static void Main()
{
try
{
new Thread (Go).Start();
}
catch (Exception ex)
{
// We'll never get here!
Console.WriteLine ("Exception!");
}
}
static void Go() { throw null; }
将上述代码修改为
public static void Main()
{
new Thread (Go).Start();
}
static void Go()
{
try
{
...
throw null; // this exception will get caught below
...
}
catch (Exception ex)
{
Typically log the exception, and/or signal another thread
that we've come unstuck
...
}
}
将是处理异常的好人选。
有人问我,“除了上述线索,还有哪些其他替代方案适合作为好的解决方案?很难找到替代方案,所以我在这里提出它以收集您的建议。
【问题讨论】:
标签: c# multithreading