Sign in Join
Wiki copytemporary

Revision 1 of 1, by Kai Burghardt on 8-6-2022. The page as it is now.

Try/fi

Varattu sana try on osa joko try..finally lohkoa tai try..except-lohkoa.

Jos poikkeus tapahtuu, kun koodia suoritetaan try:n ja finally:n välillä, suoritusta jatketaan finally. Jos poikkeusta ei tapahdu, myös finally ja end:n välinen koodi suoritetaan.

pascal
try
  // koodi, joka saattaa aiheuttaa poikkeuksen
finally 
  // suoritetaan aina viimeisenä
end;

Vain poikkeuksen sattuessa except:n ja end:n välinen koodi suoritetaan.

pascal
try
  // koodi, joka saattaa aiheuttaa poikkeuksen
except 
  // toteutetaan vain poikkeus tapauksessa
  on E: EDatabaseError do
    ShowMessage( 'Database error: '+ E.ClassName + #13#10 + E.Message );
  on E: Exception do
    ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message );
end;

Katso myös


From the Free Pascal wiki, page "Try/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.