Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2006, 09:10 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default Try Catch not working??

Hello everyone,
   I have an application that utilizes the Crystal Reports viewer and have everything working fine, but I have run into a very strange problem, simply my Try Catch statement when I load a report does not seem to be working??

try
{
     loadReport();
}
catch(Exception ex)
{
     //send email alerting me an error
}

The crystal report is generating an internal error: "Failed to open a record set" and it is not occuring at any line in code but in the crystal report (I assume inside the report viewer control). Is there anyway that I can capture this error so that my users aren't presented with the Compiler Error screen??

"The one language all programmers understand is profanity."
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old September 18th, 2006, 12:53 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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]
 
Old September 18th, 2006, 01:32 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Adam,
   Thanks alot I searched and searched but could not find that reference, much appreciated!

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 18th, 2006, 06:54 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sometimes all it takes is a fresh set of eyes, glad I could help.

- Adam Kahtava [http://adam.kahtava.com]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Try...Catch lowell VB.NET 3 July 23rd, 2007 06:35 AM
Try catch exception ayazhoda VB.NET 2002/2003 Basics 4 May 10th, 2007 10:27 AM
catch the alerts catchrohith Classic ASP Basics 1 October 26th, 2006 06:39 AM
Try and Catch? mujju PHP How-To 2 January 20th, 2005 12:27 PM
Try... Catch... End Try stu9820 ASP.NET 1.0 and 1.1 Basics 4 April 3rd, 2004 11:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.