2014-02-05 42 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

相关问题