1

Hi i have a problem with exception handling in ApiController.

I have Ninject interceptor bound to Controller actions the problem is that interceptor never sees any exception that was thrown in/bellow Controller.

public class ControllerInterceptor : IInterceptor
    {
        private DbContextTransaction transaction;

        public void Intercept(IInvocation invocation)
        {
            try
            {
                invocation.Proceed() // action will throw exception for sure
            }
            catch (Exception) // never executes even if there was exception in Proceed
            {

                throw;
            }
        }
    }        
}

My only idea is that ApiController catches all exceptions and never forwards them up so for interceptor everything looks like nothing happend. Can anyone confirm that.

Alex
  • 7,901
  • 1
  • 41
  • 56
user2184057
  • 924
  • 10
  • 27
  • 1
    have you checked (debugged) that the interceptor is ever called? If so, yes, then the implementation or another interceptor is catching all exceptions. – BatteryBackupUnit Aug 20 '14 at 18:18
  • Yes there is another interceptor in services layer (below controller) but it's catch looks like try{} catch {throw;} interceptor is being called for sure btw becouse try and finally block executes. I went as far as to make controller get method throw exception and it exectues whole try block (every instruction before and after invocation.Proceed) not seeing any exception – user2184057 Aug 20 '14 at 18:44

1 Answers1

1

Had the same problem. I used Ninject.Extensions.Interception with Ninject.Extensions.Interception.Linfu. Resolved making the action method virtual.

Zu1779
  • 2,178
  • 1
  • 18
  • 17