0

This is 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
        }
    }
}

ok this code points me to

throw, ...

how do I make it to point me to line where the function was called?

like:

using UnityEngine;
using System.Collections;

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

THO I did try doing:

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

but I get:

error CS1525: Unexpected symbol `throw'

witch is totally logical.

BUT what I can't figure out is how does Unity handle this things that it points us to functions and not throw lines?

I hope any of you has knowledge in Unity Engine

MilitaryG
  • 75
  • 1
  • 9
  • 1
    You need to read the entire stack trace. Also, don't swallow the original exception; you're hiding all information about the actual problem. http://stackoverflow.com/a/2999314/34397 – SLaks Feb 05 '14 at 21:20
  • hmmm @Slaks if I'm hiding with throw new, ... how would I point it to function witch is calling it instead of exception line? – MilitaryG Feb 05 '14 at 21:30

1 Answers1

0

If you just want the debugger to jump to the function that called Interrupt instead of jumping to Interrupt directly, you could just decorate the Interrupt method with the DebuggerStepThroughAttribute, i.e.

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

If you want to analyze this programmatically, you have to use the call stack trace.

Georg
  • 5,626
  • 1
  • 23
  • 44
  • how do I do stack trace? – MilitaryG Feb 05 '14 at 21:31
  • In the call stack trace, you only get a string that you then have to analyze by your own. – Georg Feb 05 '14 at 21:34
  • I get 2 errors: ** Assets/Scripts/SomeClass.cs(48,10): error CS0246: The type or namespace name `DebuggerStepThrough' could not be found. Are you missing a using directive or an assembly reference? ** – MilitaryG Feb 05 '14 at 21:41
  • Assets/Scripts/SomeClass.cs(48,10): error CS0246: The type or namespace name `DebuggerStepThroughAttribute' could not be found. Are you missing a using directive or an assembly reference? – MilitaryG Feb 05 '14 at 21:42
  • I'm sorry this is area witch completely I don't understand. – MilitaryG Feb 05 '14 at 21:43
  • The DebuggerStepThroughAttribute is defined in the System.Diagnostics namespace of mscorlib, at least in .NET 4.0, but I guess it's the same in other versions. – Georg Feb 05 '14 at 21:51