Grazie in anticipo del suggerimento !<div><br></div><div>in questa linea di codice provoco un oveflow volutamente</div><div>tuttavia il generico try & catch non lo cattura</div><div>come posso ovviare a questo ?</div><div>
<br></div><div>dopo l'incremento posso ottenere artificialmente una eccezione</div><div>ma mi serviva in automatico , senza controllo con la if ?</div><div><br></div><div>grazie</div><div>claudio</div><div><br></div><div>
<br></div><div><div>using System;</div><div><br></div><div> class<span class="Apple-tab-span" style="white-space:pre">        </span>uno</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> static int Main ( )</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> sbyte bit8 = 127 ;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> Int32 i = 10 ;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> string s = i.ToString() ;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Console.WriteLine ( i ) ;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>Console.WriteLine ( s ) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>try </div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>if (++bit8<0) throw new Exception("oh god it's broken"); </div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>Console.WriteLine( ++bit8) ;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> catch (Exception ex)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>Console.WriteLine( "Overflow" );</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return 0 ;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> }</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div></div><div><br></div>