- Home /
how to properly use: 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);
}
}
ok this code points me to
throw, ...
line
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 kinda logical, ...
but how does unity do it so it points you to function instead of throw line?
Why would you want to do this? Just read the entry in the traceback above that function...
traceback?
besides if I read it back all I can see is entry point and I cannot know from where they entered this entry point of the function.
I cannot know from witch function it was called. but I must dig hard in to my code.
There's a thing called a stack trace. Look that up. It keeps a log of the stack just before the exception was thrown, and it is structured as a hierarchy of method calls, so if you look at the previous entry in the stack trace, you will find where the code entered the method that threw the error.
@sdgd the traceback is what Unity dumps into the the Debug-Log. In general it's a trace containing each individual item on the stack propagating backwards from the exception that was thrown. As long as this stays within C# you will be able to trace your problem back to it's origins (therefore trace-back).