Handle JobExecutionException in Quartz.net

后端 未结 3 1647
無奈伤痛
無奈伤痛 2021-02-12 13:34

Probably a stupid question... but here goes anyway...

I have set up quartz, and can schedule jobs, and I can confirm that jobs (implementing the IJob interface) are work

3条回答
  •  孤街浪徒
    2021-02-12 13:54

    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
    }
    

    At this point the scheduler itself will log the exception to wherever it is logging (based on the configuration).

提交回复
热议问题