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?