簡體   English   中英

如何正確使用:System.InvalidOperationException

[英]how to properly use: System.InvalidOperationException

這是Unity C#

//...
    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
    }
}

我確實嘗試過這樣做:

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

但我得到:

error CS1525: Unexpected symbol `throw'

女巫是完全合乎邏輯的。

但是我不知道的是Unity如何處理將我們指向函數而不是拋出線的事情?

希望大家對Unity Engine有所了解

如果只希望調試器跳轉到調用Interrupt的函數,而不是直接跳轉到Interrupt,則可以使用DebuggerStepThroughAttribute裝飾Interrupt方法,即

    [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
        }
    }

如果要以編程方式進行分析,則必須使用調用堆棧跟蹤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM