14-10-2007, 03:50 PM
IS there anyway to make a on error resume next on just 1 line of code?
On Error On 1 Line of Code?
|
14-10-2007, 03:50 PM
IS there anyway to make a on error resume next on just 1 line of code?
14-10-2007, 05:23 PM
I don't think so, make a new function and add only this one line of code...
14-10-2007, 05:24 PM
Major Wrote:IS there anyway to make a on error resume next on just 1 line of code? From my understanding "on error resume next" is bad mojo and would probably be best to find another way around it. What exactly is the problem?
14-10-2007, 06:24 PM
Code: Dim SuxArray() As Long
14-10-2007, 07:22 PM
Zephius Wrote:Thats what I said basicly, I dont want a on error resume next code. I want it to work just for 1 line of code.Major Wrote:IS there anyway to make a on error resume next on just 1 line of code? Spodi Wrote:Are you sure the On Error Resume Next wont act below On Error Goto 0 too? The bug is when you open for example counterstrike and have a ms game running. I just want a way around it. I will just add that line of code into a new sub and add a on error resume next there.
14-10-2007, 07:56 PM
On Error Resume Next pretty much says to just push all errors into the Err object, but keep executing the statements (don't break execution) no matter what.
On Error Goto 0 turns this state off and returns the error-handling to it's regular (if something happens, shut everything down and complain a lot) state. Also, error handling is local for every subroutine. If you put On Error Resume Next at the top of the sub, there is an implied On Error Goto 0 as soon as program execution leaves that subroutine (whether by returning a value, or by hitting an Exit Function, Exit Sub, End Function, or End Sub). The code that Spodi posted will make sure that the single line of code you put between the statements will be run no matter what, and if there is an error, it'll simply be logged in the Err object and then ignored. VB has pretty weak error handling, in my opinion. All you can really do is On Error Resume Next or On Error Goto Label, and just use If Err.Number > 0 Then to check if there even was an error.
14-10-2007, 07:57 PM
William sir, I don't think people are gonna freak out about that bug. No ones gonna tab over between a mirage game and counter strike between rounds.
14-10-2007, 08:05 PM
Sonire Wrote:William sir, I don't think people are gonna freak out about that bug. No ones gonna tab over between a mirage game and counter strike between rounds.I do.
14-10-2007, 08:11 PM
On Error Resume Next actually isn't too bad. Its kinda like a simplified, unstructured version of Try/Catch blocks.
14-10-2007, 08:23 PM
Doesn't error handling have to be turned on for every individual subroutine, though?
With C++, if you have a function inside of a try block that throws an exception, then the exception isn't just local to the function - it goes all the way back to the try block and then to the catch block (if there is one). With On Error Resume Next, don't you have to explicitly set it for every subroutine? Even if you had: Code: Sub SomeSubThatWillError() If I'm correctly remembering what I read in an article about error handling in VB, you'd have to put On Error Resume Next inside of the definition for SomeSubThatWillError(), otherwise, when you raise the error, it will cause the program execution to terminate even though the sub is within an On Error Resume Next/On Error Goto 0 block. Then again, I could be completely wrong... =x
14-10-2007, 08:38 PM
I think On Local Error Resume Next is just for the routine itself. On Error Resume Next works for the subroutines, too. Not positive, though.
|
« Next Oldest | Next Newest »
|