Mirage Source http://miragesource.net/forums/ |
|
On Error On 1 Line of Code? http://miragesource.net/forums/viewtopic.php?f=201&t=2846 |
Page 1 of 1 |
Author: | William [ Sun Oct 14, 2007 3:50 pm ] |
Post subject: | On Error On 1 Line of Code? |
IS there anyway to make a on error resume next on just 1 line of code? |
Author: | Dragoons Master [ Sun Oct 14, 2007 5:23 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
I don't think so, make a new function and add only this one line of code... |
Author: | Zephius [ Sun Oct 14, 2007 5:24 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
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? |
Author: | Spodi [ Sun Oct 14, 2007 6:24 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
Code: Dim SuxArray() As Long
On Error Resume Next MsgBox Ubound(SuxArray) On Error Goto 0 |
Author: | William [ Sun Oct 14, 2007 7:22 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
Zephius wrote: 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? 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. Spodi wrote: Code: Dim SuxArray() As Long On Error Resume Next MsgBox Ubound(SuxArray) On Error Goto 0 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. |
Author: | Aranshada [ Sun Oct 14, 2007 7:56 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
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. |
Author: | Rian [ Sun Oct 14, 2007 7:57 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
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. |
Author: | Lea [ Sun Oct 14, 2007 7:59 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
'On Error Resume Next' has it's places For example, if something you do has the potential of failing, and if it failed you want to do something and try again. Say, I want to save the file... but the folder doesn't exist. Quote: On Error Resume Next
SaveFile "SomeFolderThatDoesNotExist" 'Oh no, it will error! If Err = FolderDoesNotExistError MakeFolder "SomeFolderThatDoesNotExist" 'now it will exist SaveFile "SomeFolderThatDoesNotExist" End If |
Author: | William [ Sun Oct 14, 2007 8:05 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
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. |
Author: | Spodi [ Sun Oct 14, 2007 8:11 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
On Error Resume Next actually isn't too bad. Its kinda like a simplified, unstructured version of Try/Catch blocks. |
Author: | Aranshada [ Sun Oct 14, 2007 8:23 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
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() Err.Raise 9 ' raise subscript out of range error End Sub Sub Main() On Error Resume Next Call SomeSubThatWillError() ' this sub will error, but the error will not be caught On Error Goto 0 ' If we get here, then that means we successfully "caught" ' the error by not terminating program execution. ' But the program will never reach this point anyway. If Err.Number > 0 Then ' there was an error MsgBox "There was an error, but it was caught!" Err.Clear ' clear the error End If End Sub 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 |
Author: | Spodi [ Sun Oct 14, 2007 8:38 pm ] |
Post subject: | Re: On Error On 1 Line of Code? |
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. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |