Handling Exceptions in Code
Depending on whether you are using the Report Document object, the Windows Forms Viewer, or the Web Forms Viewer, the way you handle the exceptions will be slightly different. The two viewer controls have a predefined HandleException event that you can add code to. The Report Document object needs to have exceptions handled through a try-catch statement. If the report is passed to the viewer, and then the error occurs, then the viewer will catch the exception.
Handling Exceptions with the Viewer Controls
When handling the exception with the viewer controls, you use the viewer's HandleException event. In this event, you can typecast the event's ExceptionEventArgs.Exception parameter to an EngineException class. Once you have the EngineException class, you can check the ErrorID property to determine the type of error that occurred.
The following example demonstrates how to override the error message that is displayed if there was a problem with logging on to a database or accessing the data source. All other error messages will be left to the Crystal Report Engine to display.
private void crystalReportViewer1_HandleException(object source, CrystalDecisions.Windows.Forms.ExceptionEventArgs e)
{
if (e.Exception is EngineException)
{
EngineException engEx = (EngineException)e.Exception;
if (engEx.ErrorID == EngineExceptionErrorID.DataSourceError)
{
e.Handled = true;
MessageBox.Show _
("An error has occurred while connecting to the database.");
}
else if (engEx.ErrorID == EngineExceptionErrorID.LogOnFailed)
{
e.Handled = true;
MessageBox.Show _
("Incorrect Logon Parameters. Check your user name and password.");
}
}
}
Above copied from:
http://msdn.microsoft.com/library/de...ortsengine.asp
- Adam Kahtava [
http://adam.kahtava.com]