Si tratta di un bug in Winforms? (Testato su entrambi VS2008 e VS2010)Perché il caricamento del modulo non può rilevare l'eccezione?
private void Form1_Load(object sender, EventArgs e)
{
throw new Exception("Hey");
}
non ricevo alcun errore nel codice che, poco fa, sto cercando di formulare una soluzione per questo problema Parse a number from a string with non-digits in between
E faccio questo codice in Form1_Load:
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("X");
string s = "12ACD";
string t = s.ToCharArray().TakeWhile(c => char.IsDigit(c)).ToArray().ToString();
MessageBox.Show("Y");
int n = int.Parse(t);
MessageBox.Show(n.ToString());
}
mi chiedo perché non ha mostrato il numero. Poi sullo spostamento del codice per button1_Click ...
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("X");
string s = "12ACD";
string t = s.ToCharArray().TakeWhile(c => char.IsDigit(c)).ToArray().ToString();
MessageBox.Show("Y");
int n = int.Parse(t);
MessageBox.Show(n.ToString());
}
... poi ho notato che c'è un errore: stringa di input non era in un formato corretto.
Perché Form1_Load non ha rilevato alcuna eccezione, perché ha fallito silenziosamente? Il codice esce da form1_load all'indirizzo string t = s.ToCharArray(). TakeWhile ...
Ho corretto correttamente questo comportamento sul mio computer di sviluppo x64 Win7 SP1. Vedi [questa risposta] (http://stackoverflow.com/a/11997142/119527) per come. –