Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Posts Tagged ‘IRescueController

MonoRail, IRescueController Handle Unexpected Exception

with one comment

By default you can intercept unexpected exceptional error occur in MonoRail you can opt to render a specific view from Views/Rescues folder or let MR pick standard one such as 404 page not found …

How how about you want to log the exception then you need to build a custom controller class that implement IRescueController interface just like this:

public class RuntimeExceptionController : SmartDispatcherController, IRescueController
  public void Rescue(Exception exception, IController controller, IControllerContext controllerContext)
    // ... log via log4net ...
    // ... render & send error back home :) whatever you find helpful

// usage: simple
public class HomeController: SmartDispatcherController{
  public void Index(){
     throw new Exception("Boom !");

Written by Chorn Sokun

October 1, 2009 at 10:38 am