Ev.
Ev.

Reputation: 7589

OnExceptionAspect and async methods

I've seen that PostSharp has now introduced support for async methods on the the OnMethodBoundary aspect base class via the AllowStateMachine=true property.

I have two related questions:

  1. Can this property be set on the OnExceptionAspect or should I change my aspect to extend OnMethodBoundaryAspect instead?

  2. What is the difference between the OnExceptionAspect and the OnMethodBoundaryAspect? Should I just always use the OnMethodBoundary?

Upvotes: 2

Views: 428

Answers (1)

AlexD
AlexD

Reputation: 5101

  1. State machines are currently supported only with OnMethodBoundaryAspect, so you would need to derive from that class.

  2. OnExceptionAspect is more convenient when you need to handle different types of exceptions in different ways. You can specify the exception type to catch in OnExceptionAspect.GetExceptionType() method or in OnExceptionAspectConfiguration.ExceptionType property.

    OnMethodBoundaryAspect allows you to hook into other method boundaries like entry and exit, however it always catches the base Exception type in the catch block.

Upvotes: 2

Related Questions