This is a migrated thread and some comments may be shown as answers.

[Solved] Exception Handling

1 Answer 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marco
Top achievements
Rank 1
Marco asked on 15 Mar 2010, 03:40 PM
Hello, i'm trying to implement a exception handling system on my application.
But i'm getting an error on firebug related to grid
syntax error

what i'm trying to do catch all exception custom or not and on base controller send it a custom ascx file that will present my custom error messages.

i'm using a base controller whit the following

 protected override void OnException(ExceptionContext filterContext) 
        { 
            // Output a nice error page 
            if (filterContext.HttpContext.IsCustomErrorEnabled) 
            { 
                filterContext.ExceptionHandled = true
                this.View("Error", filterContext).ExecuteResult(this.ControllerContext); 
            } 
        } 
 
than on my child controller i have an action that is responsible for insert a new row in database, 
i have a try catch block that will catch sqlexception and throw a custom exception

after that the OnException of base controller is called and so the Error View ascx, on firebug i see the response containing the Error View Html but it is not rendered and the js error is showed in firebug.

someone now how to achieve this?

Best Regards
Marco

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 15 Mar 2010, 03:55 PM
Hello Marco,

The grid does not know how to handle the HTML which you return from the error handler. It expects JSON if the HTTP status code is 200 (which is the default case). In case of error HTTP status 500 is expected by the grid (you can test by throwing exception in the action method which feeds the grid with data for the ajax binding). Then the grid will display a message box telling that an exception has occurred. You can override that by handling the onError client-side event and preventing the default behavior.

<%= Html.Telerik().Grid()
                .ClientEvents(events => events.OnError("onError"))
%>
<script type="text/javascript">
    function onError(e) {
        e.preventDefault();

        alert("Server error!");
    }
</script>

I think that the HTTP status code remains 200 when you render the error page. I think that if you can get it to 500 the grid will properly handle the error. Then you can handle the OnError event and act accordingly.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Marco
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or