Try/es: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Try/es
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **try** es parte tanto de un bloque **try**..**[[Finally|finally]]** como de un bloque **try**..**[[Except|except]]**. | |
| 2 | + | ||
| 3 | + | Si tiene lugar una [[Exceptions|excepción]] mientras se ejecuta el código entre un **try** y un **finally**, la ejecución se resume en **finally**. Aún si no tiene lugar la excepción, el código entre **finally** y **end** se ejecutará siempre. | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | try | |
| 7 | + | // Código que podría generar una excepción. | |
| 8 | + | finally | |
| 9 | + | // Será ejecutado siempre como últimas sentencias. | |
| 10 | + | end; | |
| 11 | + | ``` | |
| 12 | + | ||
| 13 | + | Siempre que tiene lugar una excepción, se ejecutará el código que se encuentra entre **except** y **end**. | |
| 14 | + | ||
| 15 | + | ``` pascal | |
| 16 | + | try | |
| 17 | + | // Código que podría generar una excepción | |
| 18 | + | except | |
| 19 | + | // Esto se ejecutará únicamente si tiene lugar una excepción | |
| 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 | + | ## Ver además | |
| 28 | + | ||
| 29 | + | - [[Raise]] | |
| 30 | + | - [[Exception handling]] | |
| 31 | + | ||
| 32 | + | --- | |
| 33 | + | *From the Free Pascal wiki, page "Try/es", as it stood on 2020-01-31 after a change by GAN, 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).* |
