Skip to main content
deleted 16 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

There are two questions actually.

Is it ok to use goto operators, that leads outside try/catch block and what consequences may it lead to?

How can I make this code better?

start:
try
{
    oleDbDataAdapter1.Fill(myDataTable);
}
catch (Exception ex) {
    DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
    if (res == DialogResult.Retry)
    {
        goto start;
    }
}
  1. Is it ok to use goto operators, which lead outside a try/catch block? What consequences may it lead to?
  2. How can I make this code better?

There are two questions actually.

Is it ok to use goto operators, that leads outside try/catch block and what consequences may it lead to?

How can I make this code better?

start:
try
{
    oleDbDataAdapter1.Fill(myDataTable);
}
catch (Exception ex) {
    DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
    if (res == DialogResult.Retry)
    {
        goto start;
    }
}
start:
try
{
    oleDbDataAdapter1.Fill(myDataTable);
}
catch (Exception ex) {
    DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
    if (res == DialogResult.Retry)
    {
        goto start;
    }
}
  1. Is it ok to use goto operators, which lead outside a try/catch block? What consequences may it lead to?
  2. How can I make this code better?
Tweeted twitter.com/#!/StackCodeReview/status/268983586143731712
deleted 24 characters in body
Source Link
disbeliever
  • 173
  • 1
  • 1
  • 6

There are two questions actually.

Is it ok to use goto operators, that leads outside try/catch block and what consequences may it lead to?

How can I make this code better?

start:
try
{
    oleDbDataAdapter1.Fill(dataSetRTTCExcel3.main as DataTablemyDataTable);
}
catch (Exception ex) {
    DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
    if (res == DialogResult.Retry)
    {
        goto start;
    }
}

There are two questions actually.

Is it ok to use goto operators, that leads outside try/catch block and what consequences may it lead to?

How can I make this code better?

start:
try
{
    oleDbDataAdapter1.Fill(dataSetRTTCExcel3.main as DataTable);
}
catch (Exception ex) {
    DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
    if (res == DialogResult.Retry)
    {
        goto start;
    }
}

There are two questions actually.

Is it ok to use goto operators, that leads outside try/catch block and what consequences may it lead to?

How can I make this code better?

start:
try
{
    oleDbDataAdapter1.Fill(myDataTable);
}
catch (Exception ex) {
    DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
    if (res == DialogResult.Retry)
    {
        goto start;
    }
}
Source Link
disbeliever
  • 173
  • 1
  • 1
  • 6

Is it ok to use goto in catch?

There are two questions actually.

Is it ok to use goto operators, that leads outside try/catch block and what consequences may it lead to?

How can I make this code better?

start:
try
{
    oleDbDataAdapter1.Fill(dataSetRTTCExcel3.main as DataTable);
}
catch (Exception ex) {
    DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
    if (res == DialogResult.Retry)
    {
        goto start;
    }
}