所以,如果出了什么问题,我想抛出这个异常。但它表现得很奇怪。
public Calendar LoadCalendar(){
...
if (cal == null)
{
throw new NotImplementedException();
}
_lastPollTime = DateTime.Now;
...
}我期望将此异常抛到调用LoadCalendar的任何地方。相反,程序在DateTime.Now停止;因为"NotImplementedException()“。
我做错了什么?我怎么能把它扔到方法的末尾呢?
发布于 2015-01-07 09:25:54
您需要在调用堆栈的某处添加一个"catch“子句,它接收抛出的异常并以某种方式处理它。
您可以在程序的主要功能中尝试这一点:
static void Main()
{
try
{
// put existing code here
}
catch( Exception e )
{
}
}如果没有捕获,异常就没有地方可去,因此它会导致程序终止。
这些用于处理异常的指导方针可能对您有用:http://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET
发布于 2015-01-07 09:34:34
只需在DispatcherUnhandledException中订阅App.xaml.cs Class Constructor事件,就可以处理此事件中的任何应用程序异常。
public partial class App : Application
{
public App()
{
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
}
void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
////Handle your application exception's here by e.Exception.
}
}https://stackoverflow.com/questions/27815941
复制相似问题