how to get Value that cause exception

You can do like this?

int id;
if(int.TryParse(textbox.Text, out id)
{
   //Do something
}
else
{
    MessageBox.Show(textbox.Text);
}

You can also use as earlier suggestet a try catch to catch a exception and show the textbox.Text in the catch.

EDIT : (After question changed direction)
To show the value that was unable to convert you can do as following.

string myValue = "some text";
int id = 0;
try
{
   id = Convert.ToInt32(myValue);
}
catch (FormatException e)
{
   MessageBox.Show(String.Format("Unable to convert {0} to int", myValue));
}

Leave a Comment