Recent

Author Topic: Loading Report Masks Exceptions  (Read 1685 times)

SandyG

  • Jr. Member
  • **
  • Posts: 93
Loading Report Masks Exceptions
« on: February 25, 2024, 05:14:01 am »
Just getting back into doing some coding with Lazarus and FP.

Was making a simple app that that calculates a formula, then allows the user to print a report with the chart on it.

Everything seems to be working fine and when a floating point calculation happens that causes and exception it was normally picked up and shown while in the IOE or the compiled application.

As soon as I load a report with something like this

Code: Pascal  [Select][+][-]
  1.      frReport1.LoadFromFile('MySimpleReport.lrf');

The application will no longer show any floating point exceptions, divide by zero, arccos(123.234) etc.

What is interesting is that IF I cause an exception in the application during runtime, they are caught! but this is ONLY UNTIL I call frReports LoadFromFile() then exceptions are masked.

Also it will not catch exception in a try/except block after the report is run.

I suspect the report is setting a mask on exceptions somewhere during runtime.

Any way to reset the exception mask once the report is loaded.

This is on Win 11 with Lazarus 3.0 (let me know what else you might need to know)

I'm a bit rusty so could be something I'm doing, but seems to be an issue with loading a report that is changing the exception handling chain or mask.

Thanks for any help!

Sandy

SandyG

  • Jr. Member
  • **
  • Posts: 93
Re: Loading Report Masks Exceptions
« Reply #1 on: February 25, 2024, 10:02:57 pm »
Maybe a better way to ask...

How does one typically modify the exception mask at runtime? Is this a possible solution?

Sandy

SandyG

  • Jr. Member
  • **
  • Posts: 93
Re: Loading Report Masks Exceptions
« Reply #2 on: February 25, 2024, 10:38:16 pm »
Dug a bit deeper and looked at the exception masks prior to the call to load the report...

It does trash the original settings and that doesn't seem like a good thing, seems like a bug and one that might not get noticed if you are using it and hoping to catch exceptions!

Will have to save and restore the state I guess

Here is what I saw dumping the mask before and after the call to load the report...

SandyG

  • Jr. Member
  • **
  • Posts: 93
Re: Loading Report Masks Exceptions
« Reply #3 on: February 29, 2024, 06:16:44 pm »
To close this out...

I saved the state an restore after the operation. This is my hack code -

Code: Pascal  [Select][+][-]
  1. procedure TMainDataEntry.PrintBtnClick(Sender: TObject);
  2. var
  3.   em_before : TFPUExceptionMask;
  4.  
  5. begin
  6.     // Do the report.
  7.     // Note that due to an issue in lazrepeorts the exception
  8.     // mask is set to ignore all. This means you can't catch any
  9.     // exceptions in the app. SO save it prior, do the report
  10.     // restore it.
  11.  
  12.     em_before := GetExceptionMask;
  13.  
  14.     // Load the report on demand, and kill it when done
  15.  
  16.     frReport1.LoadFromFile('Doolittle.lrf');
  17.     frReport1.ShowReport;
  18.     frReport1.Destroy;
  19.  
  20.     // restore the prior mask
  21.  
  22.     SetExceptionMask(em_before);
  23. end;

Thaddy

  • Hero Member
  • *****
  • Posts: 16194
  • Censorship about opinions does not belong here.
Re: Loading Report Masks Exceptions
« Reply #4 on: February 29, 2024, 08:25:12 pm »
That is not a hack, but the correct way to handle such issues.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018