ReportViewer: Catch errors

Hi, I would like to know how I can catch errors that showup on my reportviewer web server control when for instance there is a parameter whose value was not set.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can you the ReportError method of the ReportViewer control. It has an 'e' argument of type ReportErrorEventArgs, which you can use to handle the error.
For example, I have a page where I use it like this:

Protected Sub ReportViewer1_ReportError(ByVal sender As Object, ByVal e As Microsoft.Reporting.WebForms.ReportErrorEventArgs) Handles ReportViewer1.ReportError 
If TypeOf e.Exception Is AspNetSessionExpiredException Then 
e.Handled = True 
Response.Redirect(FormsAuthentication.LoginUrl, True) 
e.Handled = False 
End If 
End Sub 

Open in new window

karakavAuthor Commented:
For my case that method doesn't catch the errors. They are still poping up directly on the control.
Do you get the same error if you browse the repot using SSRS Report Manager? Because, if that's the case, the problem is with the report design, not with the report viewer control.
For wht you say in the first post, this may well be the situation.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

karakavAuthor Commented:
Actually I don't care (excuse me for the expression) where the error is comming from, I am looking for a way  of stoping ANY error from poping up on the control.
how do you want to stop it if you don't know where is coming from?
karakavAuthor Commented:
Since most of exception classes inherit Exception, I was thinking it is the case for reporting services and that catching that one would be enough but I guess I am wrong. What I meant in my earlier post was that I don't want the user to see the error message. I just want to provide a generic error message.
But that's the problem:
If the exception comes from the ReportViewer itself. you should be able to catch it using the event handler I copied above.
But, if you keep in mind that the ReportViewer ends up being an IFrame, displaying content from other site (the Reports Server), you may guess that it's possible that the error could be in the report itself, and the Viewer won't know anything about it. Believe me, I've seen it :)
So, here it doesn't matter if the exception inherits System.Exception, the important thing is to keep in mind that tthe error can be coming from the RS.
That's why I suggested the approach of checking it through Report Manager, or, I should add now, check the RS execution log, for error.
Unfortunately, if you are really sure that the code above doesn't catch the exception. I don't really see any other way.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karakavAuthor Commented:
Yeah, I am pretty sure this won't catch my exceptions as I already handled those ones that might come out from other sources than the report. And I agree with you that the errors are probably coming inside the report. The problem is that I don't know how to check the report itself for errors.
Well, for starters, you should run the report through SSRS Report Mangager and see what happens.
Also, somebody must been doing the reports definitions and development, so that person should be able to debug it.
karakavAuthor Commented:
Thanks any way.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.