On/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: On/fi
| Old | New | Line | |
|---|---|---|---|
| 1 | + | `On`-[[Keyword/fi|avainsanaa]] käytetään [[Exceptions/fi|poikkeuksen]] aiheuttaman tyypien toteamisessa. `On`-lauseke tarkistaa onko kyseessä lukuisista poikkeusluokista joku tietty.. | |
| 2 | + | ||
| 3 | + | ``` pascal | |
| 4 | + | ||
| 5 | + | try | |
| 6 | + | //mahdollisesti poikkeuksia aiheuttava koodilohko | |
| 7 | + | // ... | |
| 8 | + | except | |
| 9 | + | on {poikkeustyyppi} do begin | |
| 10 | + | // poikkeusten käsittely lohko, joka käsittelee jotkut poikkeukset | |
| 11 | + | end; | |
| 12 | + | end; | |
| 13 | + | ||
| 14 | + | ``` | |
| 15 | + | ||
| 16 | + | ``` pascal | |
| 17 | + | ||
| 18 | + | program range_error; | |
| 19 | + | {$mode objfpc} {$H+} | |
| 20 | + | {$R+} // Alue tarkastelu päälle | |
| 21 | + | uses sysutils; | |
| 22 | + | var | |
| 23 | + | i,j:integer; | |
| 24 | + | arr:array[0..9] of integer; | |
| 25 | + | begin | |
| 26 | + | try | |
| 27 | + | i := 0; | |
| 28 | + | j := 10; | |
| 29 | + | while i < j do | |
| 30 | + | begin | |
| 31 | + | inc(i); | |
| 32 | + | arr[i] := i + j; | |
| 33 | + | WriteLn( i,' ', arr[i]); | |
| 34 | + | end; | |
| 35 | + | except | |
| 36 | + | on E:ERangeError do begin | |
| 37 | + | WriteLn('Virhe: voimassa olevan alueen ylitys havaittu.'); | |
| 38 | + | WriteLn(E.Message); | |
| 39 | + | end; | |
| 40 | + | on E:Exception do // yleinen käsittelijä | |
| 41 | + | WriteLn('Caught ' + E.ClassName + ': ' + E.Message); | |
| 42 | + | end; | |
| 43 | + | WriteLn('Paina jotain näppäintä'); | |
| 44 | + | ReadLn; | |
| 45 | + | end. | |
| 46 | + | ``` | |
| 47 | + | ||
| 48 | + | ## Katso myös | |
| 49 | + | ||
| 50 | + | - [[Try/fi|Try]] | |
| 51 | + | - [[Except/fi|Except]] | |
| 52 | + | ||
| 53 | + | --- | |
| 54 | + | *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](/wiki-contact).* |
