I've created a simple MVC project, add one method:
public class HomeController : Controller
{
public async Task<string> Index()
{
var t = Task.Run(() =>
{
Debug.Print("Debug___1");
throw new Exception("Error #1");
Debug.Print("Debug___2");
});
await Task.Delay(5000);
return "ASD";
}
}
Then i run application, get "ASD" output and debug messages:
Debug___1
Exception thrown: 'System.Exception' in WebApplication2.dll
But how can I catch that exception? I've tried creating Application_Error method on global.asas, but it didn't work:
namespace WebApplication2
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
protected void Application_Error(object sender, EventArgs e)
{
Debug.Print("Catched");
}
}
}