Recent

Author Topic: try except without lazarus debugger messing it up  (Read 16505 times)

jw

  • Full Member
  • ***
  • Posts: 126
try except without lazarus debugger messing it up
« on: October 14, 2010, 08:00:42 pm »
It seems when I use a try except statement and test the code in lazarus the built in debugger ignores my error catching and uses it's own.

example

 where filename is non-existant or the user doesn't have permissions to read that file

        try

           AssignFile(fyle, filename);
           Reset(fyle, 1);
           BlockRead(fyle, data, 1);
           closefile(fyle);

        except

           error.text:= 'ERROR: Invalid Filename, File Unreadable';
           
        end;       


the debugger crashes at blockread and completely ignores my try catch is there a setting to fix this?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: try except without lazarus debugger messing it up
« Reply #1 on: October 14, 2010, 08:12:33 pm »
Add the unit SysUtils to your uses clause and try again

jw

  • Full Member
  • ***
  • Posts: 126
Re: try except without lazarus debugger messing it up
« Reply #2 on: October 14, 2010, 09:46:40 pm »
Classes, windows, SysUtils, FileUtil, LResources, Forms, Controls, Graphics,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPosition,
  SynEditHighlighter,unit2,unit3,unit4,unit5;

it's there still ignoring my try except blocks

lazarus 09.28.2 beta windows xp

the code try except blocks work when I run the program exe outside if the lazarus envrionment but otherwise the lazarus debugger stops everything ignoring my error trapping.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: try except without lazarus debugger messing it up
« Reply #3 on: October 14, 2010, 09:53:11 pm »
I think you should not use exceptions here.
Use IOResult.
See example: http://www.freepascal.org/docs-html/rtl/system/reset.html

Imants

  • Full Member
  • ***
  • Posts: 196
Re: try except without lazarus debugger messing it up
« Reply #4 on: October 15, 2010, 07:25:25 am »
Won't you need to write like this:

        try

           AssignFile(fyle, filename);
           Reset(fyle, 1);
           BlockRead(fyle, data, 1);
           closefile(fyle);

        except
          on Exception do
             error.text:= 'ERROR: Invalid Filename, File Unreadable';
           
        end;   

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: try except without lazarus debugger messing it up
« Reply #5 on: October 15, 2010, 07:47:21 am »
If the debugger stops, you may continue and enter your own exception handler.

You can instructor Lazarus to ignore this class of exceptions and enter your own exception handler without breaking in the debugger.

 

TinyPortal © 2005-2018