Exception Treatment Does Not Work

Asked

Viewed 68 times

1

When I enter letter in txtIdade, the program should return the exception message. But does not return, Visual Studio informs that there is exception without treatment.

try
{
    var conn = new OracleConnection(ConfigurationManager.AppSettings["strConexao"]);
    var comm = new OracleCommand($"insert into Nome(nome,idade,endereco) values ('{txtNome.Text}','{txtIdade.Text}','{txtEndereco.Text}')", conn);

    conn.Open();
    var reader = comm.ExecuteNonQuery();
    read();

}
catch (FormatException ex)
{
    MessageBox.Show(ex.Message, "erro");
    return; 
}
  • Do it the right way (https://answall.com/q/293843/101) and you won’t have this problem. You may have another problem, but you won’t have that one. This code is absolutely unsafe.

  • 1

    It must be because another error is happening, try putting only Exception to see which error will shoot, because he is the father of all exceptions.

  • Thanks for the answers! I changed and I worked here! I didn’t even know I was insecure, I’m at the beginning yet..

  • @Viníciusmalon Then post a reply with the changes you made that have solved your problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.