If you only need a summary of the use of the exception:
try { test(); } catch (Exception ex) { MessageBox.Show(ex.Message); }
If you want to see the entire stack trace (usually better for debugging), use:
try { test(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); }
Another method I've ever used:
private DoSomthing(int arg1, int arg2, out string errorMessage) { int result ; errorMessage = String.Empty; try {
And in your form you will have something like:
string ErrorMessage; int result = DoSomthing(1, 2, out ErrorMessage); if (!String.IsNullOrEmpty(ErrorMessage)) { MessageBox.Show(ErrorMessage); }
source share