Recent

Author Topic: What is the correct way to use a Try/Except in a Windows console application  (Read 11723 times)

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: What is the correct way to use a Try/Except in a Windows console application
« Reply #15 on: September 30, 2014, 05:30:33 pm »
Anyway, as the scenario you've painted isn't very useful.... who cares ;)

Quite agree. It's just that I've found this error a bit strange.

Even a clean, fresh re-installation of the stable version for lazarus/FPC has not solved it (see capture).

Well, thanks anyway for the test.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
I finally found the reason of the lock.

In outputfilter.pas, an unexpected exception is raised during the main Execute process. As all this part of the code is protected by a try/finally/end block, the code runs directly into the finally step. This one is supposed to clean up all the process, but apparently this is done here is an inconsistent state: so, the lock.

Anyway, this module (outputfilter.pas) is no more present in the trunk version. It seems that 'EnableNewExtTools' is now always set by default. So, no need to introduce an unnecessary bug report for the 1.2.4 version of Lazarus...


BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Mmm; it might affect an upcoming 1.2.6 version if the fix hasn't been backported (no idea if it has)...

I'll give it a go with Lazarus fixes 1.2 probably tomorrow and see.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

ChrisF

  • Hero Member
  • *****
  • Posts: 542
If I can help, just tell me...

Here are the concerned steps. As written before, the lock occurred in the 'finally' part of the 'try' block; though I've not investigate further when I've seen that this whole unit is not used any more in the trunk version.

Code: [Select]
function TOutputFilter.Execute
...
  try
    ...
    ReadLine(OutputLine,false);                       <-- Error raised in the try block
    ...
  finally
    {$IFDEF VerboseOFExecute}
    WriteLn('TOutputFilter.Execute W1');
    {$ENDIF}
    if FUpdating then                                 <--
      EndUpdate;                                      <-- Lock
    CleanUpExecute;                                   <--
  end;
...

procedure TOutputFilter.ReadLine
...
  end else if (ofoSearchForFPCMessages in Options) and (ReadFPCompilerLine(s))    <-- coming from here...
...

function TOutputFilter.ReadFPCompilerLine
...
  Result:=CheckForUrgentMessages(i);                  <-- and here...
...

function CheckForUrgentMessages
...
  if (ofoExceptionOnError in Options) then            <-- raised here,
    RaiseOutputFilterError(NewLine);                  <-- the first time only (see RaiseOutputFilterError)
...

procedure TOutputFilter.RaiseOutputFilterError(const Msg: string);
begin
  if FHasRaisedException then exit;
  FHasRaisedException:=true;
  raise EOutputFilterError.Create(Msg);
end;


A quick and dirty fix for me was to put the 'ReadLine' call itself in a 'try' block:
Code: [Select]
  try
    ReadLine(OutputLine,false);
  except
    // Do nothing
  end;

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

funk247

  • New Member
  • *
  • Posts: 33
Sorry its been a couple of days since you all responded, removing the LCL units fixed the problem and the script now runs perfectly. Many thanks!

Regarding the ExtractStrings function, the final boolean argument allows it to return blank strings, essential for my purposes. The facility doesn't appear to be documented in the Lazarus CCR, but I'm glad it was there as it saved me a bit of hassle :)

http://www.freepascal.org/docs-html/rtl/classes/extractstrings.html

However if you mouseover the code in the Lazarus GUI, it shows up in the tooltip, see the attached screenshot.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
The facility doesn't appear to be documented in the Lazarus CCR, but I'm glad it was there as it saved me a bit of hassle :)

http://www.freepascal.org/docs-html/rtl/classes/extractstrings.html
Actually it's the FPC RTL (run-time library) though the help file may be hosted on the same server that hosts Lazarus CCR files. Your screenshot confirms that - see the source location of the function containing RTL (and FPC)

That mouseover also indicates it is located in c:\fpctrunk which suggests you're using FPC  trunk/2.7.1 Nothing wrong with that but the function may have been extended from the one in latest stable, 2.6.4.
The documentation tracks latest stable, not trunk, so that may be the cause of the missing parameter...

If not (ie if it is also in 2.6.4) it's a bug in the documentation and should be raised...

Thanks
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

ChrisF

  • Hero Member
  • *****
  • Posts: 542
If not (ie if it is also in 2.6.4) it's a bug in the documentation and should be raised...

It's not present in the 2.6.4 version: I'm getting an error when compiling this function with FPC 2.6.4 (Lazarus 1.2.4):

csv2sql.lpr(82,5) Error: Wrong number of parameters specified for call to "ExtractStrings"


Reported it
http://bugs.freepascal.org/view.php?id=26814

Thanks.

 

TinyPortal © 2005-2018