处理异常,在自定义计时器作业的execute()中记录 [英] Handling Exceptions,Logging inside a execute() of custom timer job

查看:90
本文介绍了处理异常,在自定义计时器作业的execute()中记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Am currently having a 1 WFE and 1 SQL SERVER in my dev environment, and i have created a medium complex custom timer job for on-prem web appln.

我正在通过使用以下代码访问Web Appln和站点collec变量来进行列表处理:

 i am doing the list manipulation by accessing the web appln and site collec variables by using the below code:

///< summary>
        ///执行rilt计时器作业的方法
        ///</summary>
        ///< param name ="ContentDatabaseID"></param>
       公共重写void Execute(Guid ContentDatabaseID)
        {
            SPWebApplication webApp = this.Parent作为SPWebApplication;
           字符串strwebappname = webApp.Name.ToString();

            PerformManipulationList1(objlist1);

/// <summary>
        /// execute method of rilt timer job
        /// </summary>
        /// <param name="ContentDatabaseID"></param>
        public override void Execute(Guid ContentDatabaseID)
        {
            SPWebApplication webApp = this.Parent as SPWebApplication;
            string strwebappname = webApp.Name.ToString();

            PerformManipulationList1(objlist1);

            PerformManipulationList1(objlist2);

            PerformManipulationList1(objspdoclib1);

          PerformManipulationList1(objdoclib2);  

   }

   }

 现在我的问题是 如何在这些方法中处理异常?我也想在每种方法中记录异常.

 now my question is  how to handle exceptions within these methods? i also wanna log the exceptions inside each method.

这里的问题是,如果我将exp.message投掷到catch块中,下面的方法将不起作用,它将直接进入execute()的主要catch块中.

the doubt here is, if i put throw exp.message inside catch block , the below method will NOT work, it will directly go into the main catch block of execute().

如果第一个方法无法运行,如何避免停止执行otehr方法?

how to avoid stopping of execution of otehr methods , if in case first method fails to run?

#可能这是一个愚蠢的问题,但需要建议. :

#may be this is a silly question, but advice needed. : 

推荐答案

您好,本杰明,

您可以使用try-catch来满足此要求,但不要使用throw内部捕获.只需在catch中写出异常,而不是抛出.

在这种情况下,无论第一个方法是否失败,以下方法都将执行.

最好的问候


这篇关于处理异常,在自定义计时器作业的execute()中记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆