Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,
I am using try..catch for error handling. I am getting the message displayed as
messagebox.show (ex.tostring)

But it gives very long message.
Is it possible just to get only the actual error or I could give my own modified message, based on what ex contains?

Thanks
Posted
Comments
Herman<T>.Instance 13-Mar-12 7:32am    
ex.Message ?
Furqan Sehgal 13-Mar-12 7:45am    
right......... it works.
Thanks
ZurdoDev 13-Mar-12 7:58am    
Yes, you can give your own message. But the long message is the error message. Are you just wanting to provide a more user friendly message?
OriginalGriff 13-Mar-12 8:25am    
ToString includes the stack trace with the error description - Message just returns the description.

Try:
VB
MessageBox.Show(ex.Message) 
 
Share this answer
 
Types of messages available in Messagebox.show()

1. MessageBox.Show("Dot Net Perls is awesome.")


2. ' Show a two-argument dialog box with this method.

MessageBox.Show("Dot Net Perls is awesome.", _
"Important Message")

3. ' Use a three-argument dialog box with MessageBox.Show.
' ... Also store the result value in a variable slot.

Dim result1 As DialogResult = MessageBox.Show("Is Dot Net Perls awesome?","Important Question",MessageBoxButtons.YesNo)

4. ' Use four parameters with the method.
' ... Use the YesNoCancel enumerated constant and the Question icon.
'
Dim result2 As DialogResult = MessageBox.Show("Is Dot Net Perls awesome?","Important Query",MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
5. ' Use five arguments on the method.
' ... This asks a question and you can test the result using the variable.

Dim result3 As DialogResult = MessageBox.Show("Is Visual Basic awesome?",
"The Question",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

6. ' Use if-statement with dialog result.
'
If result1 = DialogResult.Yes And _
result2 = DialogResult.Yes And _
result3 = DialogResult.No Then
MessageBox.Show("You answered yes, yes and no.") ' Another dialog.
End If

7. ' Use MessageBox.Show overload that has seven arguments.
'
MessageBox.Show("Dot Net Perls is the best.", _
"Critical Warning", _
MessageBoxButtons.OKCancel, _
MessageBoxIcon.Warning, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.RightAlign, _
True)


8. ' Show a dialog box with a single button.
'
MessageBox.Show("Dot Net Perls is super.", _
"Important Note", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation, _
MessageBoxDefaultButton.Button1)
 
Share this answer
 
Comments
Simon_Whale 14-Mar-12 6:47am    
I believe the OP's question was about displaying the message from the execption, but not about how to use the messagebox. But throught description of the messagebox methods

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900