The requested page is not available for the requested platform. You are viewing the content for Default platform.

Handle Server-Side Errors in the Report Designer

  • 5 min to read

This document describes how to handle Report Designer server-side errors. It also explains how to display detailed error information instead of a generic "Internal Server Error" message.

The following table lists the classes and interfaces that allow you to process errors in the Report Designer.

Control

Class (Default Implementation)

Interface

Report Designer

ReportDesignerExceptionHandler

IReportDesignerExceptionHandler

Built-in Document Viewer

WebDocumentViewerExceptionHandler

IWebDocumentViewerExceptionHandler

Query Builder

QueryBuilderExceptionHandler

IQueryBuilderExceptionHandler

Handle Unknown Exceptions

The Report Designer displays the "Internal Server Error" message in a browser for all exceptions except FaultException and DocumentCreationException. For instance, such unknown exceptions occur when you try to open a broken report layout or a file that does not exist.

All the classes listed above provide the GetUnknownExceptionMessage method that is called whenever an unknown exception is raised. You can override this method to return a custom text or the Exception.Message property's value as shown in the following example.

using System;
using System.IO;
using DevExpress.XtraReports.Web.ReportDesigner.Services;
using DevExpress.XtraReports.Web.WebDocumentViewer;
using DevExpress.XtraReports.Web.QueryBuilder.Services;

public class CustomReportDesignerExceptionHandler : ReportDesignerExceptionHandler {
    public override string GetUnknownExceptionMessage(Exception ex) {
        if (ex is FileNotFoundException) {
#if DEBUG
            return ex.Message;
#else
            return "File is not found.";
#endif
            }
        return ex.GetType().Name + " occurred. See the log file for more details.";
        }
    }
}

public class CustomWebDocumentViewerExceptionHandler : WebDocumentViewerExceptionHandler {
    public override string GetUnknownExceptionMessage(Exception ex) {
        return ex.GetType().Name + " occurred. See the log file for more details.";
    }
}

public class CustomQueryBuilderExceptionHandler : QueryBuilderExceptionHandler {
    public override string GetUnknownExceptionMessage(Exception ex) {
        return ex.GetType().Name + " occurred. See the log file for more details.";
    }
}

Handle FaultException

The Report Designer shows the Exception.Message property's value when FaultException occurs (for instance, when you pass an invalid URL to a report storage).

Use the GetFaultExceptionMessage method to return a custom message for these exceptions as demonstrated below.

using System;
using System.ServiceModel;
using DevExpress.XtraReports.Web.ReportDesigner.Services;

public class CustomReportDesignerExceptionHandler : ReportDesignerExceptionHandler {
    public override string GetFaultExceptionMessage(FaultException ex) {
        return "FaultException occurred: " + faultException.Message + ".";
    }
}

Handle DocumentCreationException

The Document Viewer displays the Exception.Message property's value for DocumentCreationException. This exception can occur when you switch to the Report Designer's built-in Document Viewer and a report document is being generated (for instance, an error arises in the BeforePrint or AfterPrint event).

You can override the WebDocumentViewerExceptionHandler.GetDocumentCreationExceptionMessage method to return a custom text as shown below.

using DevExpress.XtraReports.Web.WebDocumentViewer;

public class CustomWebDocumentViewerExceptionHandler : WebDocumentViewerExceptionHandler {
    public override string GetDocumentCreationExceptionMessage(DocumentCreationException ex) {
        return "An exception occurred while document creation.";
    }
}

Handle All Exceptions

You can implement the following interfaces to handle all server-side errors independently from their types.

Each interface contains the GetExceptionMessage method that is called when any server-side error occurs.

The code snippet below demonstrates how to implement these interfaces and return custom text.

using System;
using System.IO;
using DevExpress.XtraReports.Web.QueryBuilder.Services;
using DevExpress.XtraReports.Web.ReportDesigner.Services;
using DevExpress.XtraReports.Web.WebDocumentViewer;

public class CustomExceptionHandler : IReportDesignerExceptionHandler, 
    IWebDocumentViewerExceptionHandler, IQueryBuilderExceptionHandler {
    public string GetExceptionMessage(Exception ex) {
        return ex.GetType().Name + " occurred. See the log file for more details.";
    }
}

Register Exception Handlers

To register the implemented exception handlers, use the following static methods at the application's startup.

void Application_Start(object sender, EventArgs e) {
    // ...
    DevExpress.XtraReports.Web.WebDocumentViewer.DefaultWebDocumentViewerContainer.
        Register<IWebDocumentViewerExceptionHandler, CustomWebDocumentViewerExceptionHandler>();
    DevExpress.XtraReports.Web.ReportDesigner.DefaultReportDesignerContainer.
        Register<IReportDesignerExceptionHandler, CustomReportDesignerExceptionHandler>();
    DevExpress.XtraReports.Web.QueryBuilder.DefaultQueryBuilderContainer.
        Register<IQueryBuilderExceptionHandler, CustomQueryBuilderExceptionHandler>();
}
See Also