Skip to Content
avatar image
Former Member

Bag Crystal Reports for VS 13.0.18

Hello all!

I have a many reports CrystalReports. In these files exists few bad files. Files are bad, because they have invalid function. I load each the file so:

CrystalDecisions.CrystalReports.Engine.ReportDocument doc;
doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
try
{
doc.Load("D:\\Temp_01\\Test.rpt");
}
catch (Exception ex)
{
MessageBox.Show("ErrorTest");
return;
}
catch{  MessageBox.Show("ErrorTest");  return;}

but this code causes an error (image).

The program breaks down. Block TRY ignore errors CrystalReports. I want ignore bad files and open a good files. How this do?

except.png (9.9 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    May 24, 2017 at 08:26 PM

    Hi Artem,

    Add a Catch on the Exception also so you can get to the InnerException:

    try
    {
    rpt.Load(rptName.ToString(), OpenReportMethod.OpenReportByTempCopy);

    catch (Exception ex)
    {
    if (ex.Message.ToString() == "Load report failed.")
    {
    MessageBox.Show("ERROR: Load report failed: " + ex.InnerException.Message.ToString());
    return;
    }
    if (ex.Message.ToString() == "Object reference not set to an instance of an object.")
    MessageBox.Show("ERROR: Object reference not set to an instance of an object.");
    else
    if (ex.Message.ToString() == "External component has thrown an exception.")
    {
    MessageBox.Show("ERROR: External component has thrown an exception.");
    }
    else
    {
    {
    if (ex.InnerException.Message != null)
    {
    MessageBox.Show("ERROR: " + ex.Message + " ;" + ex.InnerException.Message);

    .....

    Of course variations will work also....

    Don

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 21, 2017 at 05:21 PM

    Hi Artem,

    Using Try/Catch should get you the info you need and then go back to the loop and try to reopen a new report:

    catch (Exception ex)
    {
    if (ex.Message.ToString() == "Load report failed.")
    {
    MessageBox.Show("ERROR: Load report failed.");
    btnOpenReport.Enabled = true;
    btnSaveRptAs.Enabled = false;
    ViewReport.Enabled = false;
    btnCloserpt.Enabled = false;
    ViewReport.Enabled = false;
    btnSetPrinter.Enabled = false;
    btnPOController.Enabled = false;
    btnPrintToPrinter.Enabled = false;
    return;
    }
    if (ex.Message.ToString() == "Object reference not set to an instance of an object.")
    MessageBox.Show("ERROR: Object reference not set to an instance of an object.");
    else
    if (ex.Message.ToString() == "External component has thrown an exception.")
    {
    MessageBox.Show("ERROR: External component has thrown an exception.");
    }
    else
    {
    {
    if (ex.InnerException.Message != null)
    {
    MessageBox.Show("ERROR: " + ex.Message + " ;" + ex.InnerException.Message);

    }
    else
    {
    MessageBox.Show("ERROR: " + ex.Message);
    }
    }
    }

    Don

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Don,
      Block try/catch does not catch the mistake. This error is not managed for block try/catch. This error does crash for my program though I use try/catch. I seem that this error is the bag of Crystal Reports. Example:

      CrystalDecisions.CrystalReports.Engine.ReportDocument doc;
      doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
      try
      {
      doc.Load("D:\\Temp_01\\Test.rpt");
      }
      catch (Exception ex)
      {
      MessageBox.Show("ErrorTest");
      return;
      }
      catch{  MessageBox.Show("ErrorTest");  return;}<br>

      When this elusive error arises in this example then block "CATCH" does not work.

      Thanks,

      Artem Sol