Finally [v1.1.14+]

Ensures that one or more statements are always executed after a Try statement finishes.

Finally Statement
Finally
{
    Statements
}

논평

finally를 사용할 때마다 위에 있는 try (또는 catch) 서술문에 (연관되어 있어야) 속해야 합니다. finally는 언제나 가장 가까운 위의 try 서술문에 속합니다. block이 사용되어 그 행위가 변경된 경우는 제외합니다.

Try 서술문은 catch 또는 finally가 존재하는가에 따라 다르게 행동합니다. 더 자세한 정보는 Try를 참조하십시오.

Goto, break, continue 그리고 returntry 블록 안의 제어 흐름 지시어를 억제하려면 꼭 필요하지만 finally 블록을 종료하는 데는 사용할 수 없습니다. 예를 들어, tryreturn 42를 사용한다면, finally 블록이 실행된 후 값 42가 반환됩니다. 다음 명령어 중 하나를 사용하여 finally 블록을 빠져 나오려는 시도는 적재 시간에 그렇지 않으면 실행 시간에 가능하면 에러로 탐지됩니다.

[v1.1.19.02] 이전에서, finally 서술문이 존재하면 try 안의 제어 흐름 서술문이 작동하지 못하는 버그가 있었습니다. Returnfinally 안에서 허용되는 버그가 있었지만, 예외를 던져도 무시되었습니다.

Finally statements are not executed if the script is directly terminated by any means, including the tray menu, ExitApp, or Exit (when the script is not persistent). However, if only the current thread (not the entire script) is exiting, finally statements are executed.

One True Brace (OTB) 스타일을 선택적으로 finally 명령어에 사용할 수 있습니다. 예를 들어:

try {
    ...
} finally {
    ...
}

try {
    ...
} catch e {
    ...
} finally {
    ...
}

Try, Catch, Throw, 블록

예제

Demonstrates the behavior of finally in detail.

try
{
    ToolTip, Working...
    Example1()
}
catch e
{
    ; e가 담고 있는 객체에 관한 더 자세한 정보는, Catch를 참조하십시오.
    MsgBox, 16,, % "Exception thrown!`n`nwhat: " e.what "`nfile: " e.file
        . "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra
}
finally
{
    ToolTip ; 툴팁을 감춥니다
}

MsgBox, Done!

; 이 함수에 있는 Finally 블록은  청소 코드로 행위합니다.
Example1()
{
    try
        Example2()
    finally
        MsgBox, 여기는 예외에 상관없이 언제나 실행됩니다.
}

; 이 함수는 분이 홀수이면 실패합니다.
Example2()
{
    if Mod(A_Min, 2)
        throw Exception("Test exception")
    MsgBox, Example2 did not fail
}