IgnoreExceptiion.

A

Agnes

There is invalidcastexcepiton messagebox, , How Can I ignore it and disallow
it show in the program ?
Thanks alot
 
C

Cor Ligthert

Agnes,

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

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Agnes,
If you truely want to ignore it you can use a Try/Catch similar to what Ken
showed.

Try
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:

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

Try
m_response = DirectCast(m_request.GetResponse(),
HttpWebResponse)
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
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top