Advertisement
dimkiriaoks

exceptions

Nov 1st, 2022
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.83 KB | None | 0 0
  1. Program TRY_EXCEPT_STATEMENT;
  2. {$mode delphi}
  3. uses crt,sysutils;
  4.  
  5. var
  6. num:integer;
  7. run:boolean;
  8.  
  9. begin
  10.     Writeln;
  11.     run:=TRUE;
  12.    
  13.     While run do
  14.     begin
  15.         try    {if anything goes wrong in code, the program will move on to except}
  16.            write('Enter an integer here please: ');
  17.            readln(num);
  18.            writeln('VALID INPUT');
  19.            run := FALSE;
  20.         except  {The program instead of crushing, does the following code}
  21.            writeln('WRONG INPUT - PLEASE TRY AGAIN');
  22.            run := TRUE;
  23.         end;
  24.     end;
  25.    
  26.     Writeln;
  27. end.
  28.  
  29. {
  30. Program Description:
  31.   Program gets input from the user and performs
  32.   a format validation check using the try-except
  33.   statement. The program will ask for input
  34.   until the input entered is valid.
  35. }
  36. 2
  37.  
  38. Exceptions - Free
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement