StartprogrammingusingObjectPascal:TryFinally

From 흡혈양파의 번역工房
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

try finally

문법:

try
    // Start of protected code
    CallProc1;
    CallProc2;
    // End of protected code
finally
    Writeln('This line will be printed in screen for sure');
end;

try finally 방법을 사용한 나누기 프로그램입니다.

Program ExceptionHandling;

{$mode objfpc}{$H+}


uses
    {$IFDEF UNIX}{$IFDEF UseCThreads}
    cthreads,
    {$ENDIF}{$ENDIF}
    Classes
    { you can add units after this };

var
    x, y: Integer;
    Res: Double;
begin
    try
        Write('Input x: ');
        Readln(x);
        Write('Input y: ');
        Readln(y);
        Res:= x / y;
        Writeln('x / y = ', Res);

    finally
        Write('Press enter key to close');
        Readln;
    end;
end.

이제는 오류 발생 여부와는 관계없이 모든 경우에 finally .. end 부분을 실행할 것입니다.