fatal.nim 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2019 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. {.push profiler: off.}
  10. const gotoBasedExceptions = compileOption("exceptions", "goto")
  11. when hostOS == "standalone":
  12. include "$projectpath/panicoverride"
  13. func sysFatal(exceptn: typedesc, message: string) {.inline.} =
  14. panic(message)
  15. func sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
  16. rawoutput(message)
  17. panic(arg)
  18. elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
  19. import ansi_c
  20. func name(t: typedesc): string {.magic: "TypeTrait".}
  21. func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
  22. when nimvm:
  23. # TODO when doAssertRaises works in CT, add a test for it
  24. raise (ref exceptn)(msg: message & arg)
  25. else:
  26. {.noSideEffect.}:
  27. writeStackTrace()
  28. var buf = newStringOfCap(200)
  29. add(buf, "Error: unhandled exception: ")
  30. add(buf, message)
  31. add(buf, arg)
  32. add(buf, " [")
  33. add(buf, name exceptn)
  34. add(buf, "]\n")
  35. cstderr.rawWrite buf
  36. rawQuit 1
  37. func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
  38. sysFatal(exceptn, message, "")
  39. else:
  40. func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
  41. raise (ref exceptn)(msg: message)
  42. func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
  43. raise (ref exceptn)(msg: message & arg)
  44. {.pop.}