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

How to handle errors/exceptions?

6 Answers 1283 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Datamex
Top achievements
Rank 2
Datamex asked on 15 Jun 2011, 03:04 PM
Hi there,

I really want to let the users know whenever an error or exception occurs while a report is generated. I use a ReportViewer to display my reports and I have an errorlabel placed above the viewer.

It is possible, due to rights, that a user cannot retrieve certain data and therefore the viewer throws an error message, but I want to show an "informative" message in an errorlabel outside the report, above the viewer itself on the .aspx page. Whenever this error or exception occurs I want to NOT generate the report (just abort it and show no report) and display corresponding error message in the errorlabel on the aspx page.

In my code-behind of my .aspx page I have the following:
CustomReport customReport = new CustomReport();
// ...set reportparameters...
this.ReportViewer.Report = customReport;
// report is getting generated and viewer shows an error

For all of you, I don't use a ReportProcessor, so the Error event of it cannot be used. The Error event of the report itself cannot be used as well, because it's located in another DLL and not accessible in my .aspx page. So why isn't there an event such as the Error event of the ReportProcessor and report for the ReportViewer? 

I really want to solve this, because I don't want to show the users a report with only an error in it. I don't want to show the report at all if an error/exception occurs and this error/exception details should be displayed in the errorlabel.

Looking forward to a solution or workaround! Thanks in advance!

Regards,
Datamex

6 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 17 Jun 2011, 02:37 PM
Hello Datamex,

Report handling is time consuming task. Thus to improve the user experience we let the page to render and after that report handler is processing reports. At the moment when report error occurs the page is already rendered and changing control properties will not have the expected result. Thus our suggestion is to design your reports in an error proof way and eliminate any error while designing the reports.

Still if for any reason this is not applicable for your scenario. In order to check for errors to hide the report error and show custom message you have to subscribe for Report.Error event, do a test report rendering and if the error handler is fired do the necessary updates as shown in the following code snippet:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        var report = new Telerik.Reporting.Examples.CSharp.ProductSales();
        this.ReportViewer.Report = report;
        report.Error += delegate(object innerSender, ErrorEventArgs eventArgs)
        {
            this.ReportViewer.Report = null;
            this.Label1.Text = eventArgs.Exception.Message.ToString();
        };
        new ReportProcessor().RenderReport("HTML", report, null);
    }
}

Best wishes,
Peter
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
0
Wang
Top achievements
Rank 1
answered on 30 Dec 2011, 03:41 AM
Hello Peter,
    In case of the report be shown by using the Silverlight ReportViewer.
    How can I catch the report exception when  the executed mdx query against OLAP cube has exception?
    
    At this moment,I use the Telerik.Reporting Version is 5.0.11.510.

    Please see the code below
ReportService.svc
<%@ServiceHost  Service="Telerik.Reporting.Service.ReportService, Telerik.Reporting.Service, Version=5.0.11.510, Culture=neutral, PublicKeyToken=A9D7983DFCC261BE" %>

*.xaml
   
<telerik:ReportViewer x:Name="MyReportViewer"  
ReportServiceUri="../ReportService.svc"
Report="ReportLibrary.ReportFile.ReportTest, ReportLibrary"
/>

or
*.xaml.cs
this.MyReportViewer.RenderBegin += new RenderBeginEventHandler(ReportViewer_RenderBegin);
this.MyReportViewer.Report = "ReportLibrary.ReportFile.ReportTest, ReportLibrary";

I  create the report instance by using the "ReportService.svc" wcf service.
I  can only set the completely named report for the Silverlight ReportViewer's Report Property.

How should I do ?
I am in urgent need of yours help.Thanks
0
Jyoti
Top achievements
Rank 1
answered on 15 Jun 2012, 11:55 AM
Hi

I am facing time out exceptions in case the data set is large. I need to show friendly message incase there is any exception being thrown by the report. I have tried the solution provided by you, but still the error message is displayed inside the report viewer control. Can you please provide complete solution for showing friendly message in a label control when an unhandled exception occurs.

Thanks
0
Mukul
Top achievements
Rank 1
answered on 30 Apr 2013, 09:51 AM
Hi,

I have the exact same issue as Wang's (Posted on Dec 29, 2011). The reportviewer in my silverlight application fetches the report generated from service. I may get unexpected exception in which case I do NOT want to load the report with exception. Instead I would just like to display 'No Report'.
I am using version 6.2.12.1017 of Reportviewer.
Is there a way to check for the exception and prevent loading the report with exception yet? Urgently in need of a solution for this.

Thanks

0
Squall
Top achievements
Rank 1
answered on 03 May 2013, 10:53 AM
Hi guys,

I use the reportservice client to handle service related errors:
public partial class MainPage : UserControl, IReportServiceClientFactory
{
    public MainPage()
    {
        InitializeComponent();
 
        this.ReportViewer1.ReportServiceClientFactory = this;
    }
 
    ReportServiceClient IReportServiceClientFactory.Create(System.Uri remoteAddress)
    {
        var binding = new BasicHttpBinding() // or BasicHttpBinding(BasicHttpSecurityMode.Transport) overload if SSL is used
        {
            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
            ReceiveTimeout = new TimeSpan(0, 15, 0),
            SendTimeout = new TimeSpan(0, 15, 0),
            //uncomment to check the error handling mechanics
            //ReceiveTimeout = new TimeSpan(0, 0, 1),
            //SendTimeout = new TimeSpan(0, 0, 1),
        };
 
        var endpointAddress = new EndpointAddress(remoteAddress);
        var client = new ReportServiceClient(binding, endpointAddress);
        client.RenderAndCacheCompleted += new EventHandler<RenderAndCacheEventArgs>(client_RenderAndCacheCompleted);
 
        return client;
 
    }
 
    void client_RenderAndCacheCompleted(object sender, RenderAndCacheEventArgs e)
    {
        if (null != e.Error)
        {
            this.ReportViewer1.Visibility = Visibility.Collapsed;
        }
    }
}

As you see on error I collapse the viewer, another option is to show a viewer that displays no report or anything else to alert the user about the error.
0
Mukul
Top achievements
Rank 1
answered on 24 May 2013, 07:10 AM
Thanks a lot Squall. That solves my problem perfectly. Thank  you all the more as the response I got from my Telerik support correspondent was 'Catching internal report errors is not possible in Silverlight'.
Tags
General Discussions
Asked by
Datamex
Top achievements
Rank 2
Answers by
Peter
Telerik team
Wang
Top achievements
Rank 1
Jyoti
Top achievements
Rank 1
Mukul
Top achievements
Rank 1
Squall
Top achievements
Rank 1
Share this question
or