japl/nim/types/exceptions.nim

30 lines
966 B
Nim
Raw Normal View History

import objecttype
import stringtype
import strformat
2020-08-10 18:39:53 +02:00
type JAPLException* = ref object of Obj
errName*: ptr String
message*: ptr String
2020-08-10 18:39:53 +02:00
proc stringify*(self: JAPLException): string =
return &"{self.errName.str}: {self.message.str}"
proc newTypeError*(message: string): JAPLException =
result = JAPLException(kind: ObjectTypes.EXCEPTION, errName: newString("TypeError"), message: newString(message))
proc newIndexError*(message: string): JAPLException =
result = JAPLException(kind: ObjectTypes.EXCEPTION, errName: newString("IndexError"), message: newString(message))
proc newReferenceError*(message: string): JAPLException =
result = JAPLException(kind: ObjectTypes.EXCEPTION, errName: newString("ReferenceError"), message: newString(message))
proc newInterruptedError*(message: string): JAPLException =
result = JAPLException(kind: ObjectTypes.EXCEPTION, errName: newString("InterruptedError"), message: newString(message))