I know absolutely nothing about that so can't really comment. Let me see if I can clarify where I'm coming from a bit because I'm not sure whether we're arguing the same point or not. I'll probably get the syntax wrong so bear with me.Exceptions raised by invalid UDP packets can typically be ignored
This is obviously wrong:-
That's just turning error handling off. I imagine we're probaly in agreement on that though.Code:'Program starts Here On Error Resume Next ... 'Loads of lines of code
This isn't as wrong but I would argue is still bad practice:-
I used to come across that alot in my VB6 days but I still think it's bad because you don't actually know that the error being thrown is that the file is already closed. The error could be something completely different and this will carry on regardless. I guess there may be some situations where a particular line of code can only throw one type of error and you're happy to ignore it, but even then you don't know the underlying implementation won't change at some point.Code:... On Error Goto MyHandler 'Various bits of code I'm handling correctly ... On Error Resume Next 'Skip any errors because I don't care if the files already closed File.Close On Error Goto MyHandler 'More bit of code I'm handling correctly.
I would argue that this is correct:0
Here you're making sure the error is the one you want to consume before you consume it. Having a separate handler may or may not be apropriate, depending on the situation, but the point is to check the error first and make sure it's the one you think it is.Code:On Error goto MyGeneralHandler ...Various Lines of code being correctly handled On Error goto myFileCloseHandler File.Close On Error goto MyGeneralHandler ... more lines of code being correctly handled MyFileCloseHandler: If Error.code = "File Already Closed" 'Or whatever the error code for that was Resume Next MyGeneralHandler: 'Do whatever error handling you'd normally do here
I've seen that argued a lot and disagree I'm afraid. It means your just ignoring any error you weren't expecting... and they're the really dangerous ones. I guess you could check for any error after every line of code but that seems awefully innefficient to me.Well, you could do an inline error handling for the errors you expected, where the On Error Resume Next would be a perfectly justified way of handing errors.
The Shaggy v Funky Rhyme Battle
Played out 'fore the VBF cattle
The puns were displaced
by formed rhymes in their place
But I aint got a final line that'll...
...scan correctly
Turns out I'm not very good at limericks. And I don't really think the VBFers are cattle but, hey, you try coming up with a rhyme for battle just after you've eaten lunch.




Reply With Quote
