How to Send the exception message from my C# code back to the logic app

Jesse 0 Reputation points
2025-04-26T06:01:25.7533333+00:00

When I use "Call a local function" in my logic app. How do i send the exception message from my C# code back to the logic app?

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,470 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RithwikBojja 2,080 Reputation points Microsoft External Staff
    2025-05-02T05:15:10.5733333+00:00

    Hi @Jesse,

    Using below custom code, I am able to send exception as a response to logic apps:

    
    namespace trestnamespce
    
    {
    
        using System;
    
        using System.Threading.Tasks;
    
        using Microsoft.Azure.Functions.Extensions.Workflows;
    
        using Microsoft.Azure.WebJobs;
    
        using Microsoft.Extensions.Logging;
    
        public class testing
    
        {
    
            private readonly ILogger<testing> rilg;
    
            public testing(ILoggerFactory loggerFactory)
    
            {
    
                rilg = loggerFactory.CreateLogger<testing>();
    
            }
    
            [FunctionName("testing")]
    
            public Task<object> Run([WorkflowActionTrigger] string Name)
    
            {
    
                try
    
                {
    
                    rilg.LogInformation($"Hello Rithwik");
    
                    throw new InvalidOperationException($"Hello Rithwik, The Test Exception.{Name}");
    
                }
    
                catch (Exception ex)
    
                {
    
                    rilg.LogError(ex, "[testing] Exception occurred");
    
                    return Task.FromResult<object>(new
    
                    {
    
                        success = false,
    
                        errorMessage = ex.Message,
    
                        errorType = ex.GetType().Name
    
                    });
    
                }
    
            }
    
        }
    
    }
    
    

    After using the above code, build the code again.

    Design after Deploying to Azure:

    enter image description here

    Output:

    Screenshot 2025-05-02 103941


    If this answer was helpful, please click "Accept the answer" and mark Yes, as this can help other community members.

    enter image description here

    If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.