Pascal例外处理

代码示例

2
0

pascal例外处理

Program TRY_EXCEPT_STATEMENT;
{$mode delphi}
uses crt,sysutils;

var
num:integer;
run:boolean;

begin 
    Writeln;
    run:=TRUE;
    
    While run do
    begin
        try    {if anything goes wrong in code, the program will move on to except}
           write('Enter an integer here please: ');
           readln(num);
           writeln('VALID INPUT');
           run := FALSE;
        except	{The program instead of crushing, does the following code} 
           writeln('WRONG INPUT - PLEASE TRY AGAIN');
           run := TRUE;
        end;
    end;
    
    Writeln;
end.

{ 
Program Description:
  Program gets input from the user and performs 
  a format validation check using the try-except 
  statement. The program will ask for input
  until the input entered is valid.
}

类似页面

带有示例的类似页面

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................