MsgBox(Ex.Message) how to best handle this for a code audit

Can someone help me out. I am trying to rewrite some VB .NET code from a code audit. Below is the marvelous audit messages produced by SourceForge. Can someone show me how to best rewrite the code, in order to resolve the error messages. These are two separate audit messages that point to the same code

Abstract:
The function setEnvtProperties() in frmImmediateUpdate.vb reveals system data or debugging information by calling MsgBox on line 7. The information revealed by MsgBox could help an adversary form a plan of attack.

Explanation: An internal information leak occurs when system data or debugging information is sent to a local file, console, or screen via printing or logging.

Abstract: The method setEnvtProperties() in frmImmediateUpdate.vb ignores the value returned by MsgBox on line 7, which could cause the program to overlook
unexpected states and conditions.

Explanation:
It is not uncommon for programmers to misunderstand Read() and related methods that are part of many System.IO classes. Most errors and unusual events in .NET
result in an exception being thrown. (This is one of the advantages that .NET has over languages like C: Exceptions make it easier for programmers to
think about what can go wrong.) But the stream and reaer classes do not consider it to be unusual or exceptional if only a small amount of data becomes available)



1  Private Sub setEnvtProperties()
2   Try
3     Dim strFilter As String = String.Format("Client='{0}' and Environment='{1}'", CurrentSession.ClientName, cboEnvironments.Text)
4     Dim dv As New DataView(p_tblFacetsDatabase, strFilter, "Environment", DataViewRowState.CurrentRows)

5     lblServerVal.Text = dv(0)("CroixServer")

6  Catch ex as Exception
7    MsgBox(ex.Message)
8  End Try

9  End Sub
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David L. HansenCEOCommented:
You can use multiple "Catch" statements. This would allow you to handle various exceptions on an individual basis. That way you can just share the specific information that is applicable to the situation (or ignore it if that seems best). Below is an example:

1  Private Sub setEnvtProperties()
2   Try
3     Dim strFilter As String = String.Format("Client='{0}' and Environment='{1}'", CurrentSession.ClientName, cboEnvironments.Text)
4     Dim dv As New DataView(p_tblFacetsDatabase, strFilter, "Environment", DataViewRowState.CurrentRows)

5     lblServerVal.Text = dv(0)("CroixServer")

6     Catch ex As System.IO.IOException
7          LogException(ex) 'This would be a custom method you might build 
8     Catch ex As NullReferenceException
9          MessageBox.Show("NullReferenceException: " & " No dataview object found.")
10         MessageBox.Show("Stack Trace: " & vbCrLf & ex.StackTrace)
11    Catch ex As Exception
12        ' Code that reacts to any other exception, not already caught above. 
13   End Try
14  End Sub

Open in new window

Also, "MsgBox" is an old method which is slated to be dropped by Microsoft. Instead use "Messagebox.Show".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.