On Error GoTo ... Resume Statement

์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ํ›„ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๋ฃจํ‹ด์„ ํ™œ์„ฑํ™”ํ•˜๊ฑฐ๋‚˜ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์„ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

๊ตฌ๋ฌธ:

On Error Statement diagram


On {[Local] Error GoTo Labelname | GoTo 0 | Resume Next}

๋งค๊ฐœ ๋ณ€์ˆ˜:

GoTo Labelname: ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ "Labelname" ์ค„์—์„œ ์‹œ์ž‘ํ•˜๋Š” ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๋ฃจํ‹ด์„ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.

Resume Next: ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๋ฌธ์˜ ๋‹ค์Œ ๋ฌธ์—์„œ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์„ ๊ณ„์†ํ•ฉ๋‹ˆ๋‹ค.

GoTo 0: ํ˜„์žฌ ํ”„๋กœ์‹œ์ €์˜ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Local: "On error"๋Š” ๋ฒ”์œ„๊ฐ€ ์ „์—ญ์ ์ด๋ฏ€๋กœ ๋‹ค๋ฅธ "On error" ๋ฌธ์žฅ์— ์˜ํ•ด ์ทจ์†Œ๋  ๋•Œ๊นŒ์ง€ ํ™œ์„ฑ์œผ๋กœ ๋‚จ์•„ ์žˆ์Šต๋‹ˆ๋‹ค. "On Local error"๋Š” ๊ทธ๊ฒƒ์„ ํ˜ธ์ถœํ•œ ๋ฃจํ‹ด์— ์ง€์—ญ์ ์ž…๋‹ˆ๋‹ค. ์ง€์—ญ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๋Š” ์ด์ „ ์ „์—ญ ์„ค์ •์„ ๋ฎ์–ด์”๋‹ˆ๋‹ค. ํ˜ธ์ถœํ•œ ๋ฃจํ‹ด์ด ๋๋‚˜๋ฉด ์ง€์—ญ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๋Š” ์ž๋™์œผ๋กœ ์ทจ์†Œ๋˜๋ฉฐ ์ด์ „ ์ „์—ญ ์„ค์ •์ด ๋ณต๊ตฌ๋ฉ๋‹ˆ๋‹ค.

The On Error GoTo statement is used to react to errors that occur in a macro.

์˜ˆ:


Sub ExampleReset
On Error GoTo ErrorHandler
Dim iNumber As Integer
Dim iCount As Integer
Dim sLine As String
Dim aFile As String
    aFile = "c:\data.txt"
    iNumber = Freefile
    Open aFile For Output As #iNumber
    Print #iNumber, "This is a line of text"
    Close #iNumber
    iNumber = Freefile
    Open aFile For Input As iNumber
    For iCount = 1 To 5
        Line Input #iNumber, sLine
        If sLine <>"" Then
            Rem
        End If
    Next iCount
    Close #iNumber
    Exit Sub
ErrorHandler:
    Reset
    MsgBox "All files will be closed",0,"Error"
End Sub

Please support us!