Обработка ошибок

  • Автор темы Автор темы Akupaka
  • Дата начала Дата начала
на сколько я знаю - нет, не сброситься
Создайте и выполните агента с нижеприведённым кодом. Первая функция сбрасывает ошибку, вторая — нет.
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">Код агента</div></div><div class="sp-body"><div class="sp-content">
Код:
Sub Initialize
On Error Goto ErrorMsg
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Call testErr1
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Call testErr2
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
ErrorMsg:
Msgbox Error
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
End Sub
Sub testErr1
On Error Goto ErrorMsg
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Error 1000, "Some error"
ExitSub:
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
ErrorMsg:
Msgbox Error
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Resume ExitSub
End Sub
Sub testErr2
On Error Goto ErrorMsg
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Error 1000, "Some error"
ExitSub:
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
ErrorMsg:
Msgbox Error
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
End Sub
 
Resume statement
Syntax

Resume [ 0 | Next | label ]
Elements
Usage
The Resume statement resets the values of the Err, Erl, and Error functions.

Выходит если я делаю Resume Next, то Err = 0 не надо...
 
On Error [ errNumber ] { GoTo label | Resume Next | GoTo 0 }
Resume Next

Specifies that when the error occurs, execution continues with the statement following the statement which caused the error. No error-handling routine is executed. The values of the Err, Erl, and Error functions are not reset. (Note that a Resume statement does reset these values.) The error is considered handled.
 
Medevic, а Вы не про On Error Resume Next пишете?
В 8.5 хелпе про On Error Resume Next и про Resume statement разные разделы пишут.
 
On Error Resume Next не сбрасывает ошибку, а
Код:
On Error Goto Errh
'...
Errh:
Resume Next
сбрасывает. Подтверждение:
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">Код агента</div></div><div class="sp-body"><div class="sp-content">
Код:
Sub Initialize
On Error Goto ErrorMsg
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Call testErr3
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Call testErr4
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
ErrorMsg:
Msgbox Error
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
End Sub
Sub testErr3
On Error Goto ErrorMsg
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Error 1000, "Some error"
ExitSub:
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
ErrorMsg:
Msgbox Error
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Resume Next
Sub testErr4
On Error Resume Next
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Error 1000, "Some error"
ExitSub:
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Exit Sub
ErrorMsg:
Msgbox Error
Print "" & Getthreadinfo(1) & " line " & Getthreadinfo(0) & " Err = " & Err & " Error = " & Error
Resume ExitSub
End Sub
 
Мы в соцсетях:

Взломай свой первый сервер и прокачай скилл — Начни игру на HackerLab

Похожие темы