I'm wondering what the correct way is to pass on an exception from one method to my form.
public void test()
{
try
{
int num = int.Parse("gagw");
}
catch (Exception)
{
throw;
}
}
Form:
try
{
test();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
in this way i cannot see my text box.
There are many ways, for example:
Method one:
public string test()
{
string ErrMsg = string.Empty;
try
{
int num = int.Parse("gagw");
}
catch (Exception ex)
{
ErrMsg = ex.Message;
}
return ErrMsg
}
Method two:
public void test(ref string ErrMsg )
{
ErrMsg = string.Empty;
try
{
int num = int.Parse("gagw");
}
catch (Exception ex)
{
ErrMsg = ex.Message;
}
}
try
{
// your code
}
catch (Exception w)
{
MessageDialog msgDialog = new MessageDialog(w.ToString());
}
Source: Stackoverflow.com