Try/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Try/fi
| Old | New | Line | |
|---|---|---|---|
| 1 | + | [[Reserved word|Varattu sana]] `try` on osa joko `try`..[[Finally/fi|finally]] lohkoa tai `try`..[[Except/fi|except]]-[[Block/fi|lohkoa]]. | |
| 2 | + | ||
| 3 | + | Jos [[Exceptions/fi|poikkeus]] tapahtuu, kun koodia suoritetaan `try`:n ja `finally`:n välillä, suoritusta jatketaan `finally`. Jos poikkeusta ei tapahdu, myös `finally` ja [[End/fi|end]]:n välinen koodi suoritetaan. | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | try | |
| 7 | + | // koodi, joka saattaa aiheuttaa poikkeuksen | |
| 8 | + | finally | |
| 9 | + | // suoritetaan aina viimeisenä | |
| 10 | + | end; | |
| 11 | + | ``` | |
| 12 | + | ||
| 13 | + | Vain poikkeuksen sattuessa `except`:n ja `end`:n välinen koodi suoritetaan. | |
| 14 | + | ||
| 15 | + | ``` pascal | |
| 16 | + | try | |
| 17 | + | // koodi, joka saattaa aiheuttaa poikkeuksen | |
| 18 | + | except | |
| 19 | + | // toteutetaan vain poikkeus tapauksessa | |
| 20 | + | on E: EDatabaseError do | |
| 21 | + | ShowMessage( 'Database error: '+ E.ClassName + #13#10 + E.Message ); | |
| 22 | + | on E: Exception do | |
| 23 | + | ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message ); | |
| 24 | + | end; | |
| 25 | + | ``` | |
| 26 | + | ||
| 27 | + | ## Katso myös | |
| 28 | + | ||
| 29 | + | - [[Raise]] | |
| 30 | + | ||
| 31 | + | --- | |
| 32 | + | *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](/wiki-contact).* |
