fatal.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. {.push profiler: off.}
  2. when hostOS == "standalone":
  3. include "$projectpath/panicoverride"
  4. proc sysFatal(exceptn: typedesc, message: string) {.inline.} =
  5. panic(message)
  6. proc sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
  7. rawoutput(message)
  8. panic(arg)
  9. elif defined(nimQuirky) and not defined(nimscript):
  10. import ansi_c
  11. proc name(t: typedesc): string {.magic: "TypeTrait".}
  12. proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} =
  13. var buf = newStringOfCap(200)
  14. add(buf, "Error: unhandled exception: ")
  15. add(buf, message)
  16. add(buf, arg)
  17. add(buf, " [")
  18. add(buf, name exceptn)
  19. add(buf, "]")
  20. cstderr.rawWrite buf
  21. quit 1
  22. proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
  23. sysFatal(exceptn, message, "")
  24. else:
  25. proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
  26. when declared(owned):
  27. var e: owned(ref exceptn)
  28. else:
  29. var e: ref exceptn
  30. new(e)
  31. e.msg = message
  32. raise e
  33. proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} =
  34. when declared(owned):
  35. var e: owned(ref exceptn)
  36. else:
  37. var e: ref exceptn
  38. new(e)
  39. e.msg = message & arg
  40. raise e
  41. {.pop.}