Sign in Join
Wiki copytemporary

On/fi

Deutsch · English · Suomi

On-avainsanaa käytetään poikkeuksen aiheuttaman tyypien toteamisessa. On-lauseke tarkistaa onko kyseessä lukuisista poikkeusluokista joku tietty..

pascal

try
    //mahdollisesti poikkeuksia aiheuttava koodilohko
    // ...
except
   on {poikkeustyyppi} do begin
     // poikkeusten käsittely lohko, joka käsittelee jotkut poikkeukset
   end;
end;
pascal

program range_error;
{$mode objfpc} {$H+}
{$R+} // Alue tarkastelu päälle
uses sysutils;
var
  i,j:integer;
  arr:array[0..9] of integer;
begin
  try
    i := 0;
    j := 10;
    while i < j do
      begin
        inc(i);
        arr[i] := i + j;
        WriteLn( i,'  ', arr[i]);
      end;
  except
    on E:ERangeError do begin
      WriteLn('Virhe: voimassa olevan alueen ylitys havaittu.');
      WriteLn(E.Message);
    end;
    on E:Exception do  // yleinen käsittelijä
      WriteLn('Caught ' + E.ClassName + ': ' + E.Message);
  end;
  WriteLn('Paina jotain näppäintä');
  ReadLn;
end.

Katso myös


From the Free Pascal wiki, page "On/fi", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.