error handle - vb6 against vb.net

orengolan

New member
error handle - vb6 against vb.net

is it possible to translate this vb6 code into vb.net? on error goto errHandle <my code....> errHandle: if err.number=x then resume next elseif err.number=y then resume else exist function end if i'll ask it in other words: is it a way in vb.net to get back to the place of exception or even one line after the exception, or any way of climbing up in the stack? (when i have nested functions)
 

gooshi

New member
as you probably know

Goto is officialy DEAD! you can use try-catch wherever you want and decide what to do on an error First Example(in VB.NET): Public Sub Calc() Dim myAnswer As Double 'Do something Try myAnswer = Divide(5, 0) Catch ex As Exception myAnswer = 0 End Try 'Continue doing what ever you planned End Sub Private Function Divide(ByVal mone As Int32, ByVal mechane As Int32) As Int32 Return mone / mechane End Function Second example, you can use different exception handling: Sub Main() Dim i As Integer = 5 Try Throw New ArgumentException() Catch e As OverflowException When i = 5 Console.WriteLine("First handler") Catch e As ArgumentException When i = 4 Console.WriteLine("Second handler") Catch When i = 5 Console.WriteLine("Third handler") End Try End Sub​
hope these examples help a little.
 

orengolan

New member
thanks, but...

thanks goosh, i know the try-catch statments, but what i need is somthing more powerfull, as vb6 has offerd: resume (returning to line of error) resume next (returning to line after the error) I can do it with try-catch with the help of loop statment, but it looks too complicated to read... is there a way to choose a line in the stack trace, and 'jump' to that specific line? GO GO vb6!
 
למעלה