0

DateUtils.TryISO8601ToDate('8', Result) generates an exception. But it is Try !!! It's task is to try without throwing any exceptions.

The problem is not that Delphi IDE reacts on this exception. The problem is that the "Try" function produces such an exception instead of returning true/false.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Paul
  • 25,812
  • 38
  • 124
  • 247
  • 7
    Kinda lame that they implement `TryISO8601ToDate` on top of `ISO8601ToDate` instead of the other way around ..... Sloppy, and indicative of a lack of cohesion and experience in the library developers. Where are the old heads doing code review that would immediately see such a mistake? – David Heffernan Mar 03 '17 at 09:21

1 Answers1

3

I think you may need to adjust your IDE debugger options.

In the IDE go to Tools | Options and on the Language Exceptions tab below Debugger Options | Embarcadero Debuggers, uncheck the Notify on Language Exceptions box.

With that box checked, the debugger will stop execution in the IDE before your (or the RTL's) exception-handling executes. It pops up a dialof asking whether you want to break execution or continue. If you choose the latter, the exception handler in the code will then execute.

Update Tbh, with the updates to your q, I'm not at all clear what you are saying is the problem. Which part of the following code does not behave as you expect/wish and how?

procedure TForm1.TestISODates;
var
  S : String;
  DT : TDateTime;
begin
  DT := Now;
  S := DateToISO8601(DT, False);
  Caption := S;

  if TryISO8601ToDate(S, DT, False) then
    Caption := 'OK';

  S := 'banana';
  if TryISO8601ToDate(S, DT, False) then
    Caption := 'OK'
  else
    Caption := S + ' not ok';
end;
MartynA
  • 30,454
  • 4
  • 32
  • 73
  • Yes, those notifications can really be surprising. – Tom Brunberg Mar 03 '17 at 09:03
  • @TomBrunberg: Indeed. Personally, I find it the most irritating of all Delphi default settings with the sole exception of `LogInPrompt` = True in all flavors of database connection components. – MartynA Mar 03 '17 at 09:08
  • When the exception dialog pops up you can also click the 'ignore this exception' type box and it won't pop up again. – Dsm Mar 03 '17 at 09:15
  • 5
    You see, the problem is not that Delphi IDE reacts on this exception. The problem is that the "Try" function produces such an exception. – Paul Mar 03 '17 at 09:20
  • @Paul I don't have the source to hand, but I bet that the try function calls the non-try, and catches the exception. Is that so? In which case the try function won't raise an exception. Or am I wrong? – David Heffernan Mar 03 '17 at 10:43
  • 1
    @Paul, OK now I've looked at the source. And the try variant calls the non-try variant, as I hypothesised, and wraps it in a swallow all try/except. So what you are reporting makes no sense at all, and I am voting to close the question accordingly, off-topic since the reported behaviour cannot be reproduced. – David Heffernan Mar 03 '17 at 11:25