0

my goal is to catch all unhandled exceptions. For this purpose, I created Asp.Net Core 3.0 application and added a test method with recursion to the controller

(it is dummy method was made for test purpose only)

        [HttpGet("test")]
        public ActionResult Test()
        {
            try
            {
                Test();
            }
            catch (Exception ex)
            {
                throw;
            }
            return Ok();
        }

To catch all unhandled exceptions I subscribed to currentDomain.UnhandledException += CurrentDomain_UnhandledException;, and redirected error handling to the error controller

            if (env.IsDevelopment())
            {
                //app.UseDeveloperExceptionPage();
                app.UseExceptionHandler("/api2/error-local-development");
            }
            else
            {
                app.UseExceptionHandler("/api2/error");
                app.UseHsts();
            }

I thought it should be enough to handle all exceptions even stackoverflow but when I execute the script below the application crashes and I can't intercept this moment.

 curl -i -H "Accept: text/html" https://localhost:44374/api/test

is there a way how to catch this exception and handle it?

DL-Newbie
  • 146
  • 1
  • 9
  • any error message? – Roman Marusyk Oct 28 '20 at 21:48
  • 2
    A StackOverflowException cannot be handled as such. – user2864740 Oct 28 '20 at 21:49
  • @RomanMarusyk- here is a message from curl ``` curl -i -H "Accept: text/html" https://localhost:44374/api/test curl: (56) Send failure: Connection was reset``` and here is a VS Output dump: ``` ... The program '[10192] iisexpress.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'. The program '[1068] Ams.Client.Host.exe' has exited with code -1 (0xffffffff). ``` – DL-Newbie Oct 28 '20 at 23:45
  • @user2864740 stackoverflow it one of the rest exceptions and if you tall that I can't catch this exception in the unhandled exception handler - I'd like to ask links where I could read about that? – DL-Newbie Oct 28 '20 at 23:52
  • 1
    Short answer: https://stackoverflow.com/a/1599238/2864740 , https://learn.microsoft.com/en-us/dotnet/api/system.stackoverflowexception — some of the why’s in https://blog.adamfurmanek.pl/2018/04/07/handling-stack-overflow-exception-in-c-with-veh/ – user2864740 Oct 29 '20 at 00:03
  • 1
    A little bit more into SEH-class exceptions, corruption, and why .NET doesn’t handle them: https://www.hexacta.com/advanced-exceptions-in-net/ — such SEH-class exceptions are generally process (or at least appdomain) fatal. A SOE is an even further special case. – user2864740 Oct 29 '20 at 00:11

0 Answers0