Q:

Async await returns to caller before ContinueWith, but only when exception is thrown

Let's say I have two async methods, first one calls second one
[HttpPost]
[Authorize]
public async Task<ActionResult> Run(Job job)
{
    await JobHub.RunJobAsync(job);
    return View(job);
}   

public static async Task RunJobAsync(job)
{
    try
    {
        await someAsyncMethodThatReturnsVoidTask()
            .ContinueWith(t => someCosoleLoggingCode());
    }
    catch (Exception ex)
    {
        someExceptionHandlingCode();
    }
}

When no exception occurs, everything in RunJobAsync(job) runs to completion before returning to Run(job). The problem is that whenever an exception occurs in someAsyncMethodThatReturnsVoidTask(), the control returns back to Run(job) before the code in ContinueWith is executed! This also happens if I get rid of ContinueWith and just use await. Is there a way to make sure the code in ContinueWith is executed before returning to caller, regardless of whether an exception occurs?
Edit: I'm not saying the code in ContinueWith() doesn't execute, it still does, but only after the calling method Run(Job) resumes and the breakpoint return View(job); is hit

A:

I know what's wrong with my code, the line return View(job); is being hit before ContinueWith() due to the subsequent form submit that cancels the task (and thus generates the OperationCanceledException). If you come here having a related problem this will only help you if your cancel button is also a submit button.

