stack trace


Node.js

  1. function foo() {
  2. throw new Error('failed')
  3. }
  4. try {
  5. foo()
  6. } catch(err) {
  7. console.trace(err)
  8. }

Output

  1. Trace: Error: failed
  2. at foo (/Users/bob/examples/stack_trace.js:2:9)
  3. at Object.<anonymous> (/Users/bob/examples/stack_trace.js:6:3)
  4. at Module._compile (internal/modules/cjs/loader.js:688:30)
  5. at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
  6. at Module.load (internal/modules/cjs/loader.js:598:32)
  7. at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
  8. at Function.Module._load (internal/modules/cjs/loader.js:529:3)
  9. at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
  10. at startup (internal/bootstrap/node.js:285:19)
  11. at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
  12. at Object.<anonymous> (/Users/bob/examples/stack_trace.js:8:11)
  13. at Module._compile (internal/modules/cjs/loader.js:688:30)
  14. at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
  15. at Module.load (internal/modules/cjs/loader.js:598:32)
  16. at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
  17. at Function.Module._load (internal/modules/cjs/loader.js:529:3)
  18. at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
  19. at startup (internal/bootstrap/node.js:285:19)
  20. at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

Go

  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. "runtime/debug"
  6. )
  7. func foo() {
  8. panic(errors.New("failed"))
  9. }
  10. func main() {
  11. defer func() {
  12. if r := recover(); r != nil {
  13. fmt.Println(string(debug.Stack()))
  14. }
  15. }()
  16. foo()
  17. }

Output

  1. goroutine 1 [running]:
  2. runtime/debug.Stack(0xc000090eb8, 0x10a8400, 0xc00007e1c0)
  3. /Users/mota/.gvm/gos/go1.11/src/runtime/debug/stack.go:24 +0xa7
  4. main.main.func1()
  5. /Users/bob/examples/stack_trace.go:16 +0x46
  6. panic(0x10a8400, 0xc00007e1c0)
  7. /Users/mota/.gvm/gos/go1.11/src/runtime/panic.go:513 +0x1b9
  8. main.foo(...)
  9. /Users/bob/examples/stack_trace.go:10
  10. main.main()
  11. /Users/bob/examples/stack_trace.go:20 +0xa2