问题描述
可能是一个愚蠢的问题......但在这里不用反正...
Probably a stupid question... but here goes anyway...
我已经建立了石英,并可以安排工作,我可以确认,工作( 。实现IJob接口)正在
I have set up quartz, and can schedule jobs, and I can confirm that jobs (implementing the IJob interface) are working.
看着网站上的文档(教程的第三课):
Looking at the documentation on the site, (Lesson 3 of the tutorial):
这是你被允许从执行方法抛出异常的唯一类型是 JobExecutionException
。
我想,当发生异常,我还没有明确的处理,那么就应该抛出一个JobExecutionException,这样我就可以在父应用程序记录它。我有我的包裹在一个try catch代码,并抛出JobExecutionException,但是现在在哪里处理呢?
I would like that when an exception occurs that I haven't explicitly handled, it should throw a JobExecutionException, so that I can log it in the 'parent' application. I have wrapped my code in a try catch, and have thrown the JobExecutionException, but now where to handle it?
我不调用execute方法的任何地方,也就是由石英处理(在一个单独的线程)。所以,当出现我怎么处理这个错误了。我真的不希望吞下错误的作业
I don't call the execute method anywhere, that is handled by Quartz (on a separate thread). So, how do I handle that error when it occurs. I don't really want to swallow the error in the Job
推荐答案
通常,您将设置作业的执行方法如下:
Typically you would set up the execute method of your job as follows:
try
{
// the work you want to do goes here
}
catch (ExceptionTypeYouWantToHandle1 ex1)
{
// handle exception
}
catch (ExceptionTypeYouWantToHandle2 ex2)
{
// handle exception
}
// and so on
catch (Exception ex)
{
// something really unexpected happened, so give up
throw new JobExecutionException("Something awful happened", ex, false); // or set to true if you want to refire
}
此时调度设置为true本身将记录该异常到无论它是记录(基于该配置)。
At this point the scheduler itself will log the exception to wherever it is logging (based on the configuration).
这篇关于处理JobExecutionException在Quartz.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!