Try-catch flow to handle two failing services We need to create a car with apiCar and log in two places CosmosDB and the logger, whether there is an error or not. Except if the error happens in Cosmos, in that case we only log in the logger. Finally, if there is an exception, any exception, we need rethrow it so the &quot;MyFunction&quot; caller can handle it.
This is my best shot that works but I don't like it. Is there any way to improve it?
public async Task MyFunction(Car car)
{
    try
    {
        var apiCar = await _APIService.CreateAsync(car);
        car.Status = CarStatus.Created;

        _logger.LogInformation(&quot;Created apiCar for car: {carId}&quot;, car.Id);
    }
    catch (ApiErrorException exception)
    {
        _logger.LogError(exception, &quot;API exception for car: {carId}&quot;, car.Id);
        car.Status = CarStatus.Error;
        car.ErrorMessage = exception.Body.Error.Message;
    }
    catch (Exception exception)
    {
        _logger.LogError(exception, &quot;Exception for car: {carId}&quot;, car.Id);
        car.Status = CarStatus.Error;
        car.ErrorMessage = exception.Message;
    }

    try
    {
        await _cosmosService.UpdateItemAsync(car);
    }
    catch (CosmosException exception)
    {
        _logger.LogError(exception, &quot;Cosmos exception for car: {carId}&quot;, car.Id);

        throw;
    }

    if (car.Status == CarStatus.Error)
    {
        throw new Exception();
    }
}
First, any async function should end with Async, ie MyFunctionAsync. You can see examples of this in the other async functions you're calling throughout your code.
As to your requirements, the exception you throw at the end is devoid of any useful information. It has no exception origination information (line number etc) and no correct stack trace. Either save the exception you're handling in the top try when it happens, or even better rethrow it on the spot.
I very much question your updating the item even though the first part errored out, so rethrowing the first set of exceptions on the spot is what I'd do, but if you want to update it even in an error case, bring the update function with you in the catch and then rethrow.
The second part is fine, you're rethrowing as you should.