views:

90

answers:

1

Hello all,

I'm writing a custom error-handling method, and am passing it an Exception object. I need to be able to access that Exception's ExceptionContext object, so I can set a property to true before I execute the Error view. Does anyone know how to get to the ExceptionContext, given just an Exception object?

For reference, the reason I need the ExceptionContext object is so I can perform the code below:

filterContext.ExceptionHandled = true; // filterContext is of type ExceptionContext
this.View("Error_partial", filterContext.Exception).ExecuteResult(this.ControllerContext);

I've read online that ExceptionHandled must be set to true, or the following statement will throw a yellow screen of death, rather than the friendly "Error_partial" page I'd like it to. So it's important that I be able to access the ExceptionContext of the Exception. Any help would be great appreciated.

Thanks.

A: 

Unless you have an existing ExceptionContext object already;

You should create one and pass your Exception object to it, then it will create an ExceptionContext based on the Exception object you passed it.

Look here

Tony
@Tony, I guess I did think about doing this, but I wondered if the ExceptionContext's associated properties would still be the same. Obviously if I create a new one, wouldn't the properties be reset? Maybe it doesn't matter, given what I'm trying to do...
Mega Matt
@Mega Matt, from what I understand in the MSDN library, it says it will use the current Exception object to create a new object, so if it needs to set any properties I guess it would do so. I am not sure however...
Tony