Skip to content

Instantly share code, notes, and snippets.

@codehaks
Created September 15, 2017 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehaks/16a78967c5e01d2844fe817d4ce04d4a to your computer and use it in GitHub Desktop.
Save codehaks/16a78967c5e01d2844fe817d4ce04d4a to your computer and use it in GitHub Desktop.
Simulating Error handling in ASP.NET Core
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace ErrorDemo {
public class Startup {
public void Configure (IApplicationBuilder app) {
app.UseDeveloperExceptionPage();
app.UseExceptionHandler ("/error");
app.Use (async (context, next) => {
if (context.Request.Path == "/throw") {
throw new Exception ("Something went wrong!");
}
await context.Response.WriteAsync (Environment.NewLine + " No Error");
await next.Invoke ();
});
app.Run (async (context) => {
await context.Response.WriteAsync (Environment.NewLine + context.Request.Path);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment