Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with file IO #29

Open
targetoid opened this issue Jan 19, 2021 · 0 comments
Open

Problem with file IO #29

targetoid opened this issue Jan 19, 2021 · 0 comments

Comments

@targetoid
Copy link

I have a problem with file operations, specifically when there is an exception while writing to a file (when the file does not exist in this instance). When I call Reset(F); on a non existing file, the program just crashes with no message. This only happens after I execute some JavaScript code.

I noticed that in BESENShell, you are calling the Reset function like this {$i-}reset(f,1);{$i+};. Why is it necessary to supress thrown exceptions like this? Are there any other situations, where I can run into this error?

Here is some code that results in a crash. Thanks for your help.

program BESENTest;

{$APPTYPE CONSOLE}

uses
  SysUtils, BESEN, BESENValue, BESENTypes, BESENASTNodes, BESENNativeObject, BESENNumberUtils;

var
  lResult : TBESENValue;
  lResultStr: String;
  lBesen : TBESEN;
  F: file of char;

  function BesenValToStr(aBesenVal : TBESENValue):string;
  begin

    case aBesenVal.ValueType of
      bvtUNDEFINED:     Result := '';
      bvtNULL:          Result := '<null>';
      bvtBOOLEAN:       Result := BoolToStr(aBesenVal.Bool);
      bvtNUMBER:        Result := FloatToStr(aBesenVal.Num);
      bvtSTRING:        Result := aBesenVal.Str;
      bvtOBJECT:        Result := '<object>';
      bvtREFERENCE:     Result := '<reference>';
      bvtLOCAL:         Result := '<local>';
      bvtNONE:          Result := '<none>';
    end;
  end;

begin
  try
    lBesen := TBESEN.Create();
    try
      lResult := lBesen.Execute('1+1');
      lResultStr := BesenValToStr(lResult);
      Writeln(lResultStr);
    finally
      lBesen.Free;
    end;

    AssignFile(F,'doesnotexist.log');
    try
      try
        Reset(F);
        //{$i-}Reset(f);{$i+};
      finally
        CloseFile(F);
      end;
    except
      on Ex: Exception do
        Writeln(Ex.Classname, ': ', Ex.Message);
    end;

    ReadLn;

  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant