Raise/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Raise/fi
| Old | New | Line | |
|---|---|---|---|
| 1 | + | [[Reserved word/fi|Varattua sanaa]] `raise` käytetään [[Exceptions/fi|poikkeuksen]] "heittämiseen". `Raise` lauseke pysäyttää ohjelman normaalin suorittamisen ja siirtää ohjauksen poikkeuksen käsittelijälle. | |
| 2 | + | ||
| 3 | + | ## Lyhyt yhteenveto | |
| 4 | + | ||
| 5 | + | - Kuuluu [[object-oriented programming/fi|olio-ohjelmointiin]] | |
| 6 | + | - Aiheuttaa poikkeuksen | |
| 7 | + | ||
| 8 | + | ## Esimerkki | |
| 9 | + | ||
| 10 | + | ``` pascal | |
| 11 | + | program Example1; | |
| 12 | + | uses sysutils; | |
| 13 | + | ||
| 14 | + | function titleread(a_title:string):string; | |
| 15 | + | var | |
| 16 | + | answer:string; | |
| 17 | + | begin | |
| 18 | + | writeln ( a_title); | |
| 19 | + | readln(answer); | |
| 20 | + | ||
| 21 | + | if answer = '' then raise Exception.Create('Variable has no value'); | |
| 22 | + | result := answer; | |
| 23 | + | end; | |
| 24 | + | ||
| 25 | + | var | |
| 26 | + | firstname,lastname:string; | |
| 27 | + | ||
| 28 | + | begin | |
| 29 | + | firstname := titleread( 'Write your first name:'); | |
| 30 | + | lastname := titleread( 'Write your last name:'); | |
| 31 | + | writeln ('your name is ', firstname, ' ', lastname); | |
| 32 | + | readln; | |
| 33 | + | end. | |
| 34 | + | ``` | |
| 35 | + | ||
| 36 | + | ## Katso myös | |
| 37 | + | ||
| 38 | + | - [[Try/fi|Try]]..[[Finally/fi|finally]] [[Block/fi|lohko]]. | |
| 39 | + | - [[Try/fi|try]]..[[Except/fi|except]] lohko. | |
| 40 | + | - [[On/fi|on]] | |
| 41 | + | - [[runtime error/fi|run-time error]] | |
| 42 | + | ||
| 43 | + | --- | |
| 44 | + | *From the Free Pascal wiki, page "Raise/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).* |
