Дзюндзя ([info]syarzhuk) wrote,
@ 2007-07-17 16:17:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Entry tags:code, vb6, Праграмізм

Funny bug
You would think that "next line" after the condition that raises an error would be the line after "End If", not the one right after "Then"...

On Error Resume Next
Dim c As Collection
   'comment out to show the bug
   'Set c = New Collection
   'c.Add "Shit"
   'since c wasn't initialized, accessing it's property raises an error
   'you'd think that Resume Next will go to the line after End If, but...
   If c.Count > 0 Then
      MsgBox "Shit happened"
   End If



(Post a new comment)


[info]ppk_ptichkin
2007-07-17 08:31 pm UTC (link)
Гы.

(Reply to this)


[info]ygam
2007-07-17 09:05 pm UTC (link)
Did you write this code?

(Reply to this) (Thread)


[info]syarzhuk
2007-07-17 09:15 pm UTC (link)
Я чужой баг, основанный на этом, сегодня пофиксил.
Подумал, что если бы VB6 использовали ещё где-нибудь, кроме нашей странной компании (справедливости ради - это legacy, вся новая разработка на сишарпе), то это был бы чудный вопрос для интервью - как может быть, что код внутри IFа выполняется, когда условие IFа не евалюейтится в True?

(Reply to this) (Parent)(Thread)


[info]ppk_ptichkin
2007-07-18 01:25 am UTC (link)
Это так и надо, или баг в VB?

(Reply to this) (Parent)(Thread)

On Error Resume Next - зло!
[info]xpeh1
2007-07-18 06:40 am UTC (link)
Это так и надо, t.e. by design, так как стоит
On Error Resume Next
выполняется следующая строка, а именно
Msgbox...
Вот еще примеры:
http://www.developerfusion.co.uk/show/4325/
http://www.cpearson.com/excel/ErrorHandling.htm

(Reply to this) (Parent)(Thread)

Re: On Error Resume Next - зло!
[info]syarzhuk
2007-07-18 12:11 pm UTC (link)
You'd think that the 'next line' is the line after End If, not the first line in the Then block...

(Reply to this) (Parent)(Thread)

Re: On Error Resume Next - зло!
[info]ppk_ptichkin
2007-07-18 02:21 pm UTC (link)
Если я правильно помню, то в BASIC'e оператор есть строчка (правда, последний раз я запачкался об BASIC лет 20 назад..)

(Reply to this) (Parent)(Thread)

Re: On Error Resume Next - зло!
[info]emeraid
2007-07-19 03:50 pm UTC (link)
Зато теперь есть VB.NET, и можно уже перестать ругать забытый Богом BASIC. :-)

(Reply to this) (Parent)(Thread)

Re: On Error Resume Next - зло!
[info]ppk_ptichkin
2007-07-19 04:19 pm UTC (link)
:-)

octal forever.

(Reply to this) (Parent)

Re: On Error Resume Next - зло!
[info]syarzhuk
2007-07-19 06:31 pm UTC (link)
В Vb.Net та же хрень
On Error Resume Next
If False And (Nothing.GetType().IsArray) Then
   Console.WriteLine("This line should never be printed because False And anything is False")
End If

(Reply to this) (Parent)(Thread)

Re: On Error Resume Next - зло!
[info]emeraid
2007-07-19 06:35 pm UTC (link)
Хм, таки да. Я никогда его не употребляю, обычно использую
Try

Catch ex As Exception
'MessageBox.Show(ex.Message)
End Try

(Reply to this) (Parent)

Re: On Error Resume Next - зло!
[info]ppk_ptichkin
2007-07-19 07:00 pm UTC (link)
Ну дык.

Надо полагать, NEXT был определён как следующая строчка в самом первом варианте языка, где-нибудь на светлой памяти CP/M, чтоб не сказать бОльшего. А поменять это определение таперича никак нельзя, ибо поломается газильоны газильёнбитов никому ненужных корпоратвиных макросов.

(Reply to this) (Parent)

Re: On Error Resume Next - зло!
[info]ppk_ptichkin
2007-07-18 01:54 pm UTC (link)
какая, всё-таки, гадость эта ваша заливная рыба.

(Reply to this) (Parent)


[info]emeraid
2007-07-19 06:43 pm UTC (link)
Вместо:
If c.Count > 0 Then
MsgBox "Shit happened"
End If

Я бы написала:
If c.Count <= 0 Then
Else
MsgBox "Shit happened"
End If

(Reply to this)


Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…