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

ReportBook and Error handling

1 Answer 50 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 14 Aug 2012, 09:37 AM
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?

1 Answer, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 14 Aug 2012, 03:20 PM
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 !

What am I doing wrong?
Tags
General Discussions
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Share this question
or