callstack

Does Go have an “infinite call stack” equivalent?

折月煮酒 提交于 2019-12-01 19:54:06
I'm a newbie to Go, coming from Node.JS. In Node, if I run this: function run(tick = 0) { if (tick < 1000000) { return run(tick + 1); } return 0; } console.log(run()); The program will crash because the maximum call stack size was exceeded. If I do this in Go: package main import "fmt" func run(tick int) (int) { if (tick < 1000000) { return run(tick + 1) } return 0 } func main() { fmt.Println(run(0)) } This will run and print 0 to stdout. My questions are: Is there a maximum number of calls above which the Go example I gave would fail? Is code like this an anti-pattern in Go? In Go, goroutines

Does the JS callstack always have at least one frame?

只谈情不闲聊 提交于 2019-12-01 18:48:51
I've recently seen a presentation on the JS event loop which is, frankly, brilliant, but I have a lingering question now about the JS call stack. If you think about the global execution context as, say, main(), is main() never resolved? My reasoning here is that, if it were, then the JS program would be complete, and no callbacks would happen. --edit My primary interest here is how the call stack is represented, in relation to the callback queue. If the event loop is said to wait until the call stack is empty before pushing new frames onto the stack, then the loop would be waiting until the

Retrieve the caller instance (not class) of a method or constructor

混江龙づ霸主 提交于 2019-12-01 18:00:40
Is it possible to retrieve the caller instance of a method/constructor? This question has already been posted, but each time the answers are talking about caller Class (using stacktrace) and not caller instance. If a solution exists, it can be really convenient to build object graph (with a common super type) and handle parent child navigation with default constructor. public class TestCallStack { public static class BaseClass { BaseClass owner; // //ok, this is the correct way to do it // public BaseClass(BaseClass owner) { // this.owner = owner; // } public BaseClass() { //this.owner = ?????

Retrieve the caller instance (not class) of a method or constructor

感情迁移 提交于 2019-12-01 16:17:12
问题 Is it possible to retrieve the caller instance of a method/constructor? This question has already been posted, but each time the answers are talking about caller Class (using stacktrace) and not caller instance. If a solution exists, it can be really convenient to build object graph (with a common super type) and handle parent child navigation with default constructor. public class TestCallStack { public static class BaseClass { BaseClass owner; // //ok, this is the correct way to do it //

maximum call stack size exceeded - no apparent recursion

拜拜、爱过 提交于 2019-12-01 10:26:48
I've spent about 12 hours looking through this code, and fiddling with it, trying to find out where there's a recursion problem because I'm getting the, "maximum call stack size exceeded," error, and haven't found it. Someone smarter than me please help me! so far, all I found was that when I make the object, spot , a circle , object, the problem disappears, but when I make it a, 'pip', I get this stack overflow error. I've gone over the pip class with a friggin' microscope, and still have no idea why this is happening! var canvas = document.getElementById('myCanvas'); //----------------------

Get run time type of stack frames

笑着哭i 提交于 2019-12-01 08:18:27
I was wondering if it were possible to obtain the run time type of method callers in the stack trace. Consider the following example: class Parent { public void Foo() { var stack = new StackTrace(); foreach (var frame in stack.GetFrames()) { var methodInfo = frame.GetMethod(); Console.WriteLine("{0} (ReflectedType: {1})", methodInfo.ToString(), methodInfo.DeclaringType); } } } class Child : Parent { } If I create an instance of Child and call Foo var child = new Child(); child.Foo(); Foo will print: Void Foo() (ReflectedType: Parent) Is there any way to get the actual run time types (Child in

Efficient way to determine whether a particular function is on the stack in Python

て烟熏妆下的殇ゞ 提交于 2019-12-01 06:46:10
For debugging, it is often useful to tell if a particular function is higher up on the call stack. For example, we often only want to run debugging code when a certain function called us. One solution is to examine all of the stack entries higher up, but it this is in a function that is deep in the stack and repeatedly called, this leads to excessive overhead. The question is to find a method that allows us to determine if a particular function is higher up on the call stack in a way that is reasonably efficient. Similar Obtaining references to function objects on the execution stack from the

In Python, how do I inspect and then re-raise an exception while maintaining the original call stack?

狂风中的少年 提交于 2019-12-01 03:48:39
I've got a situation where I'm catching a specific exception type, inspecting the exception's message to check if it's actually an exception I want to catch, and then re-raising the exception if not: try: # do something exception-prone except FooException as e: if e.message == 'Something I want to handle': # handle the exception else: raise e This works fine, with one problem. In the case I re-raise the exception, that exception now occurs at the line I re-raised it (i.e. at raise e ), rather than at the location the exception originally occurred. This isn't ideal for debugging, where you want

Programatic access to call stack in .net

本秂侑毒 提交于 2019-12-01 03:01:19
How can I get programmatic access to the call stack? Try System.Diagnostics.StackTrace . James Avery You can use the StackTrace and StrackFrame classes in System.Diagnostics . Scott Dorman The right way is to use the StackTrace and StackFrame classes. Throwing an exception just to get the stack trace is completely misusing exceptions. 来源: https://stackoverflow.com/questions/13434/programatic-access-to-call-stack-in-net

Efficient way to determine whether a particular function is on the stack in Python

匆匆过客 提交于 2019-12-01 02:58:40
问题 For debugging, it is often useful to tell if a particular function is higher up on the call stack. For example, we often only want to run debugging code when a certain function called us. One solution is to examine all of the stack entries higher up, but it this is in a function that is deep in the stack and repeatedly called, this leads to excessive overhead. The question is to find a method that allows us to determine if a particular function is higher up on the call stack in a way that is