fatal.nim 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. when nimvm:
  26. # TODO when doAssertRaises works in CT, add a test for it
  27. raise (ref exceptn)(msg: message & arg)
  28. else:
  29. writeStackTrace()
  30. var buf = newStringOfCap(200)
  31. add(buf, "Error: unhandled exception: ")
  32. add(buf, message)
  33. add(buf, arg)
  34. add(buf, " [")
  35. add(buf, name exceptn)
  36. add(buf, "]\n")
  37. cstderr.rawWrite buf
  38. quit 1
  39. proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
  40. sysFatal(exceptn, message, "")
  41. else:
  42. proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
  43. raise (ref exceptn)(msg: message)
  44. proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
  45. raise (ref exceptn)(msg: message & arg)
  46. {.pop.}