StartprogrammingusingObjectPascal:TryFinally

From 흡혈양파의 번역工房
Revision as of 10:18, 26 July 2012 by Onionmixer (talk | contribs) (SPOP TryFinally 페이지 추가)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 부분을 실행할 것입니다.