Re: Visual Basic 2010 - Unhandled Exceptions, Please Help
If you know where the exception is occurring, I think you can put "On Error Resume Next" on the line above, and it will contimue to the next line. Not sure why you would want to ignore exceptions though!
Re: Visual Basic 2010 - Unhandled Exceptions, Please Help
First off you should never use On Resume Next, as it is bad to ignore errors. Instead use assertion i.e.
This is not good if the file does not exist.
Code:
IO.File.Delete("Somefile.txt")
Best to check if the file exists first, this is assertion.
Code:
Dim fileName As String = "Somefile.txt"
. . .
If IO.File.Exists(fileName) Then
IO.File.Delete(fileName)
End If
For unexpected exceptions you can override the default unhandled exception handler, see attached VS2010 project, compile, run outside of the IDE then inside the IDE. Next look at the error log file created in the app executable folder.
Bottom line is write tight code, test well and when there is an unexpected error write assertion to trap for this and as a last resort use Try/Catch and never leave the Catch section empty.
Re: Visual Basic 2010 - Unhandled Exceptions, Please Help
Thanks.
On Resume Goto Next worked... lol
Errors are created by user input, hard to explain but the error is unavoidable,
and a msg box for it could go bad/several, + handling it may create negative effects/wait/lag
the error has an ending statement ending on error goto next for all, so no loops.
Re: Visual Basic 2010 - Unhandled Exceptions, Please Help
Originally Posted by VBbbq
Thanks.
On Resume Goto Next worked... lol
Errors are created by user input, hard to explain but the error is unavoidable,
and a msg box for it could go bad/several, + handling it may create negative effects/wait/lag
the error has an ending statement ending on error goto next for all, so no loops.
On Resume anything is bad bad bad, this statement is a left over from VB6.
In regards to errors are unavoidable, this is because you are not using assertion.
Re: Visual Basic 2010 - Unhandled Exceptions, Please Help
Originally Posted by VBbbq
hard to explain but the error is unavoidable
I rather doubt either of those assertions. Maybe if you were to actually show and tell us what you're doing and what exception is being thrown then we could help you handle the situation properly.
Re: Visual Basic 2010 - Unhandled Exceptions, Please Help
example code with issue:
If inputidval.Text <> "" And inputid.Checked Then
On Error Resume Next
WebBrowser1.Document.GetElementById(inputidval.Text).SetAttribute("Value", inputidnew.Text)
End If
End Sub
when the user puts in a name thats not valid, it would return errors
if the name they put in wasnt available in webbrowser1.document
not sure how to resolve it other than the on error resume next thing, it
worked, is there a better solution?
im not sure how to write the io.file.exists statement for WebBrowser1.Document.GetElementById(inputidval.Text).SetAttribute("Value", inputidnew.Text)
sounds hard.. :/
heres a working snippet / example app code
Dim CodeElements As HtmlElementCollection = WebBrowser1.Document.All
For Each codeElement As HtmlElement In CodeElements
Dim code2Element As String = codeElement.GetAttribute("src").ToString
If code2Element <> "" And codeid.Checked Then
txtID.Text += "HTML SOURCE: "
txtID.Text += code2Element
txtID.Text += vbCrLf
numElement += 1
txtElements.Text = numElement
End If
when the first TextBox contains an ID that doesn't exist. The solution is simple and you have already been provided with it. Simply assign the result of GetElementById to a variable and then test whether that variable is Nothing. If it is then the ID doesn't exist so you don't call SettAttribute. If it's not then you call SetAttribute on the variable. ALWAYS look before you leap, i.e. test the data before you use it and only use it if it's valid. There are very few scenarios where you can't do so.