Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a timer job which is pretty standard. Like any timer job execution of it can sometimes fail. If this happens in job status (Central Admin) the timer job status is failed.

I would like to be able to catch this type of failure in my job definition and hookup a built in event, such as onFail or onError - is this type of thing possible?

share|improve this question
    
Can you please specify which SharePoint version are you using? 2010 / 2007? –  SPArchaeologist Nov 8 '11 at 10:08
    
SharePoint 2010. –  JL01 Nov 8 '11 at 23:15
    
Only thing that comes to mind is either: a) simulate the handler inside the timer job (if this is possible) and then force the timer job status as failed; b) force a second esecution of the timer job with the Retry job definition parameter; c) force the execution of another timer job using the new RunNow job definition method (and leaving the original job in a failed status). I know this isn't much, but at the moment nothing better comes to mind. I will try and search for a more elegant solution (I had a similar problem in the past, so I'm on the same boat here...) –  SPArchaeologist Nov 9 '11 at 9:26

1 Answer 1

I would suggest using a try { } catch { } block on your Execute function. In the catch I would have it record the error message to the ULS log (or email you if thats what you want) and then throw the exception.

The ensures you log and/or are notified of the failure but the failure is also seen on the timer job in Central Admin.

So, something like:

public override void Execute(Guid targetInstanceId)
{
    base.Execute(targetInstanceId);
    try
    {
        // Timer Job Code to Execute
    }
    catch (Exception exception)
    {
        // write to ULS or email
        throw exception;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.