Faire un peu de pratique dans VS2010.ThrowException n'existe pas dans le contexte actuel
travailler avec un try/catch/finally et faire passer le message suivant:
Exception ne Throw existe pas dans le contexte actuel. Ai-je manqué une instruction using pour utiliser ThrowExcpetion?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static string[] eTypes = { "none", "simple", "index", "nested index" };
static void Main(string[] args)
{
foreach (string eType in eTypes)
{
try
{
Console.WriteLine("Main() try");
Console.WriteLine("Throwing: \"{0}\") Called.",eType);
ThrowException(eType);
Console.WriteLine("Main() try continuing");
}
catch (System.IndexOutOfRangeException e)
{
Console.WriteLine("Main System.indexoutofrange catch",
e.Message);
}
finally
{
Console.WriteLine("Main finally");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
Qu'est-ce que 'ThrowException()'? Ce n'est pas une méthode intégrée, où la définissez-vous? – BoltClock
Si vous essayez d'apprendre à gérer les exceptions, apprenez à ne pas afficher ex.Message. Utilisez ex.ToString() pour obtenir l'exception entière. –