© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
51 replies
fasadin

✅ Exception is caught, but not?

I have this piece of code

        try
        {
            await _dbContext.RunningTotals.AddAsync(new RunningTotal
            {
                Value = runningTotalDto.Value
            });

            await _dbContext.SaveChangesAsync();
            
            return new Result<OptionNone>(OptionNone.Default);
        }
        catch (Exception e)
        {
            return new Result<OptionNone>(e);
        }
        try
        {
            await _dbContext.RunningTotals.AddAsync(new RunningTotal
            {
                Value = runningTotalDto.Value
            });

            await _dbContext.SaveChangesAsync();
            
            return new Result<OptionNone>(OptionNone.Default);
        }
        catch (Exception e)
        {
            return new Result<OptionNone>(e);
        }


on
 await _dbContext.SaveChangesAsync();
 await _dbContext.SaveChangesAsync();
I am getting exception. Breakpoint hits
catch (Exception e)
catch (Exception e)
it goes into
return new Result<OptionNone>(e);
return new Result<OptionNone>(e);
and then it just skips execution... it shows on IDE that exception is still present

I don't understand nothing from it 😦
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ exception not being caught
C#CC# / help
3y ago
❔ C# Exceptions Not Caught?
C#CC# / help
3y ago
❔ Exception thrown in Rider but not in VS2022
C#CC# / help
3y ago
✅ Why is this try/catch block preventing lines after it from firing when an exception is caught?
C#CC# / help
17mo ago