I appreciate that you can catch an error raised by a report in a viewer but can you catch an error raised by a report within a reportbook displayed in a viewer?
I am pleased to say that the following code seems to enable me to trap exceptions when using a reportbook on my webpage (report being reflected) ::
o = Assembly.Load(ay).CreateInstance(fullyQualifiedClassName)
Dim evError As EventInfo = o.GetType().GetEvent("Error")
Dim HandlerMethod = Me.GetType().GetMethod("ErrorHandler")
evError.AddEventHandler(o, [Delegate].CreateDelegate(evError.EventHandlerType, Me, HandlerMethod))
Public Sub ErrorHandler(ByVal sender As Object, ByVal e As EventArgs)
Dim _reportBook As New ReportBook()
Dim _errorReport As New rptError()
_reportBook.Reports.Add(_errorReport)
**** ReportViewer1.Report = _reportBook
ReportViewer1.RefreshReport()
End Sub
However the line "****" produces the wonderful error "Object not set to an instance of object".
I have also found this event fires every time there is an exception and not just once. I thought the page was rendered first then the exception raised !