Throw [v1.1.04+]

에러가 일어났다는 신호를 보냅니다. 이 신호는 try-catch 서술문으로 잡을 수 있습니다.

Throw , Expression

매개변수

Expression

catch의 OutputVar에 저장할 값.

이 매개변수가 표현식이면, 다음은 모두 유효한 예제입니다:

throw 3
throw "literal string"
throw MyVar
throw i + 1
throw { what: "Custom error", file: A_LineFile, line: A_LineNumber } ; 객체를 던집니다.

이 매개변수는 언제나 표현식입니다. 그래서 변수 참조는 퍼센트 사인으로 둘러싸면 안됩니다. 단, double-deref를 수행할 때는 예외입니다.

[v1.1.05+]: 생략되면, 기본 메시지와 함께 예외 객체가 던져집니다.

Exception()

Creates an object with properties, also common to exceptions created by runtime errors.

Exception(Message , What, Extra)

This object contains the following properties:

What이 생략되면, 현재 함수나 서브루틴의 이름이 기본값이 됩니다. 그렇지 않으면 문자열이거나 또는 호출 스택의 위쪽으로부터 아래로 음의 오프셋일 수 있습니다. For example, a value of -1 sets Exception.What to the current function or subroutine, and Exception.Line and Exception.File to the line and file which called it. 그렇지만, 스크립트가 컴파일 되었거나 오프셋이 유효하지 않으면, What은 그냥 문자열로 변환됩니다.

MessageExtra는 문자열로 변환됩니다. 이것들은 예외가 던져졌는데 잡지 못하면 에러 대화상자에 보여집니다.

try
    SomeFunction()
catch e
    MsgBox % "Error in " e.What ", which was called at line " e.Line 

SomeFunction() {
    throw Exception("Fail", -1)
}

Try, Catch, Finally, OnError()

예제

Try 참조.