fatal.nim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. when defined(nimHasExceptionsQuery):
  11. const gotoBasedExceptions = compileOption("exceptions", "goto")
  12. else:
  13. const gotoBasedExceptions = false
  14. when hostOS == "standalone":
  15. include "$projectpath/panicoverride"
  16. proc sysFatal(exceptn: typedesc, message: string) {.inline.} =
  17. panic(message)
  18. proc sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
  19. rawoutput(message)
  20. panic(arg)
  21. elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
  22. import ansi_c
  23. proc name(t: typedesc): string {.magic: "TypeTrait".}
  24. proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
  25. writeStackTrace()
  26. var buf = newStringOfCap(200)
  27. add(buf, "Error: unhandled exception: ")
  28. add(buf, message)
  29. add(buf, arg)
  30. add(buf, " [")
  31. add(buf, name exceptn)
  32. add(buf, "]\n")
  33. cstderr.rawWrite buf
  34. quit 1
  35. proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
  36. sysFatal(exceptn, message, "")
  37. else:
  38. proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
  39. raise (ref exceptn)(msg: message)
  40. proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
  41. raise (ref exceptn)(msg: message & arg)
  42. {.pop.}