2013-10-22 170 views
1

我有這個簡單的程序演示了.NET中的異常處理,在這種情況下,我正在捕獲ArgumentOutOfRangeException,但是我傳遞給控制檯的自定義消息沒有顯示出來。自定義的異常消息不在控制檯中顯示

using System; 

class program 
{ 
static void Main() 
{ 
    int[] source = { 1, 2, 3, 4, 5 }; 
    int[] destination = { 6, 7, 8, 9 }; 

    try 
    { 
     Array.Copy(source, destination, 7); 
    } 
    catch (ArgumentOutOfRangeException e) 
    { 
     Console.WriteLine("Sorry, there is something wrong in the program ! : {0}", e.Message); 
    } 
} 
} 

,這裏是輸出截圖

enter image description here

+1

我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –

回答

8

你捉ArgumentOutOfRangeException,但該方法拋出ArgumentException
因此,您的catch塊永遠不會執行。

+0

我沒有注意到。非常感謝您的幫助 !非常感激。 – Neville