What does Try and Except mean in this code?

if node=1 then begin
         ankunftnode1:=now;
        //..................................................
        try
        thot:=(rawdata2[2]+rawdata2[3]*256)/10;
        except
        thot:=0;
        end;
        chart1.Series[1].AddXY(time,thot);

Can anyone explain it to me? Thank you...

1. If raises an exception between try .... except will be executed only statements between except .... end;
2. If does not raise any exception between try .... except it will NOT be executed statements between except .... end;

Edited 6 Years Ago by finalist: n/a

1. If raises an exception between try .... except will be executed only statements between except .... end;
2. If does not raise any exception between try .... except it will NOT be executed statements between except .... end;

I really don't understand. Making me confused... Can show any example to make more clear? Sorry to trouble you so much....

example:

function  Calc(R1, R2, R3: Real): Real;
var
  R:     Real;
begin
  try
    R := R1*R2/R3;
  except
    Result := 0;
    ShowMessage('There is an exception');
  end;
  Result := R;
end;

If there is an error when calculates R1*R2/R3 you will see a popup-message There is an exception.
If there is NOT an error when calculates R1*R2/R3 you will NOT see any popup-message.

example:

function  Calc(R1, R2, R3: Real): Real;
var
  R:     Real;
begin
  try
    R := R1*R2/R3;
  except
    Result := 0;
    ShowMessage('There is an exception');
  end;
  Result := R;
end;

If there is an error when calculates R1*R2/R3 you will see a popup-message There is an exception.
If there is NOT an error when calculates R1*R2/R3 you will NOT see any popup-message.

Ok now I understand. Thank you for explaining in detail with example.

This article has been dead for over six months. Start a new discussion instead.