Posted to tcl by oldlaptop at Sat Oct 03 18:38:58 GMT 2020view raw

  1. % proc foo {n} { if {$n >= 0} { return [::tcl::mathfunc::sqrt $n] } else { error "n must be nonnegative" } }
  2. % proc bar {n} { if {$n >= 0} { return [::tcl::mathfunc::sqrt $n] } else { return -code error "n must be nonnegative" } }
  3. % foo 2
  4. 1.4142135623730951
  5. % bar 2
  6. 1.4142135623730951
  7. % catch {foo -1} err opts
  8. 1
  9. % dict get $opts -errorinfo
  10. n must be nonnegative
  11. while executing
  12. "error "n must be nonnegative" "
  13. (procedure "foo" line 1)
  14. invoked from within
  15. "foo -1"
  16. % catch {bar -1} err opts
  17. 1
  18. % dict get $opts -errorinfo
  19. n must be nonnegative
  20. while executing
  21. "bar -1"
  22. %
  23.