Back to Devexpress

Handle a Callback Exception on the Server Side

aspnet-8879-common-concepts-callbacks-handle-callback-exceptions-handle-callback-exception-on-server.md

latest2.0 KB
Original Source

Handle a Callback Exception on the Server Side

  • Dec 27, 2023

Use the static CallbackError event to handle a callback exception thrown by a DevExpress web control on the server side.

Delegate callback exception handling to the Application_Error event handler.

csharp
void Application_Start(object sender, EventArgs e) { 
    DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
}
vb
Protected Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    DevExpress.Web.ASPxWebControl.CallbackError += AddressOf Application_Error
End Sub

In the Application_Error event handler, you can use the GetLastError() method to get the last exception’s details.

csharp
void Application_Error(object sender, EventArgs e) { 
    // Use HttpContext.Current to get a Web request processing helper 
    HttpServerUtility server = HttpContext.Current.Server; 
    Exception exception = server.GetLastError(); 
    // Log an exception 
    AddToLog(exception.Message, exception.StackTrace); 
}
vb
Private Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Use HttpContext.Current to get a Web request processing helper 
    Dim server As HttpServerUtility = HttpContext.Current.Server
    Dim exception As Exception = server.GetLastError()
    ' Log an exception 
    AddToLog(exception.Message, exception.StackTrace)
End Sub

View Example: How to handle application-level errors occurred during callbacks