2014-02-05 45 views
0

這是統一C#如何正確使用信息:System.InvalidOperationException

//... 
    public static void Interupt(int Index, string Text){ 
     try{ 
      Change(Transforms[ Index ], Text); 
     } 
     catch{ 
      throw new System.InvalidOperationException("Index: " + Index + " Is too large should be less than: " + Transforms.Count); // points me here 
     } 
    } 
} 

確定該代碼指向我

throw, ... 

我怎麼讓它指向我行,其中調用該函數?

,如:

using UnityEngine; 
using System.Collections; 

public class TestScript : MonoBehaviour { 
    void Start(){ 
     SomeClass.Interupt(5, ""); // I want it to point me here 
    } 
} 

THO我也嘗試這樣做:

return throw new System.InvalidOperationException("Index: " + Index + " Is too large should be less than: " + Transforms.Count); 

,但我得到:

error CS1525: Unexpected symbol `throw' 

女巫是完全合乎邏輯的。

但我無法弄清楚是怎麼處理這個事情,它指向我們的功能,而不是拋出線?

我希望任何人都有在Unity引擎

+1

您需要讀取整個堆棧跟蹤。另外,不要吞下原始異常;你隱藏了關於實際問題的所有信息。 http://stackoverflow.com/a/2999314/34397 – SLaks

+0

hmmm @Slaks如果我用throw new進行隱藏,...我如何將它指向函數女巫調用它而不是異常行? – MilitaryG

回答

0

知識。如果你只是想調試器跳轉到調用Interrupt,而不是跳躍,將直接中斷功能,你可以只裝點中斷方法與DebuggerStepThroughAttribute,即

[DebuggerStepThrough] 
    public static void Interupt(int Index, string Text) 
    { 
     try 
     { 
      Change(Transforms[Index], Text); 
     } 
     catch 
     { 
      throw new System.InvalidOperationException("Index: " + Index + " Is too large should be less than: " + Transforms.Count); // points me here 
     } 
    } 

如果您想以編程方式分析此問題,則必須使用調用堆棧跟蹤。

+0

我該如何做堆棧跟蹤? – MilitaryG

+0

編輯的帖子包含示例代碼 – Georg

+0

在調用堆棧跟蹤中,您只會得到一個字符串,然後您必須自行分析。 – Georg

相關問題