By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.


P: n/a
There is invalidcastexcepiton messagebox, , How Can I ignore it and disallow
it show in the program ?
Thanks alot
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a

Put your code in a Try-Catch block:

Nov 21 '05 #2

P: n/a

You should never ignore a message, however show us that codeline, so maybe
we can help you finding the right cast/convert.

Nov 21 '05 #3

P: n/a
If you truely want to ignore it you can use a Try/Catch similar to what Ken

Some poor code here
Catch ex As InvalidCastException
' don't do anything
End Try

If you use a Try/Catch be certain to use the most specific exception, as I
did with InvalidCastExceptions so you do not ignore other "more important"
exceptions. I would also consider using a When clause on the Exception, just
to ensure that I am only ignoring the most specific exception, other
exceptions may truely be exceptions & if ignored can cause significant
problems later, which are very hard to track down. Such as:

Return GetField(name)
Catch ex As COMException When ex.ErrorCode =
Return AddField(name, type)
End Try

m_response = DirectCast(m_request.GetResponse(),
Catch ex As WebException When TypeOf ex.Response Is HttpWebResponse
m_response = DirectCast(ex.Response, HttpWebResponse)
End Try
However!! as Cor suggests, I also consider this poor programming. I would
start by defining Option Strict On at the top of each of your source files.
Which will then cause you to have compile errors on lines that you may have
runtime errors on (InvalidCastException exceptions). You can then correct
these statements with the proper Cast (DirectCast), Conversion (CType, CInt,
CDbl, CStr) or other function (Object.ToString, System.Convert)

It might be easiest as Cor stated, show us the code, so we can offer the
correct construct to get your program to behave correctly & politely.

Hope this helps

"Agnes" <ag***> wrote in message
There is invalidcastexcepiton messagebox, , How Can I ignore it and
it show in the program ?
Thanks alot

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.