1
static void Main(string[] args)
{
try
{
var intValue = "test";
var test = Convert.ToInt32(intValue);
}
catch (FormatException)
{
Console.WriteLine("format exception");
throw;
}
catch (Exception)
{
}
finally
{
Console.WriteLine("finally");
}
}
據我所知,在從字符串轉換爲int的過程中,引發了一個FormatException。現在在catch塊中,我們重新拋出原始異常。爲什麼這不會被捕獲到泛型異常catch塊?如果我把try/catch放在throw上,那麼應用程序不會崩潰。爲什麼這個C#代碼會導致進程崩潰?