2020-08-13 23:39:26 +02:00
|
|
|
import objecttype
|
2020-08-23 12:10:08 +02:00
|
|
|
import stringtype
|
2020-08-23 23:48:38 +02:00
|
|
|
import strformat
|
2020-08-26 11:41:39 +02:00
|
|
|
import ../memory
|
2020-08-10 18:39:53 +02:00
|
|
|
|
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
type JAPLException* = object of Obj
|
2020-08-25 10:24:50 +02:00
|
|
|
errName*: ptr String
|
|
|
|
message*: ptr String
|
2020-08-10 18:39:53 +02:00
|
|
|
|
2020-08-13 23:39:26 +02:00
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
proc stringify*(self: ptr JAPLException): string =
|
|
|
|
return &"{self[].errName[].stringify}: {self[].message[].stringify}"
|
2020-08-23 23:48:38 +02:00
|
|
|
|
2020-08-14 10:02:13 +02:00
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
proc newTypeError*(message: string): ptr JAPLException =
|
|
|
|
result = allocateObj(JAPLException, ObjectTypes.EXCEPTION)
|
|
|
|
result.errName = newString("TypeError")
|
|
|
|
result.message = newString(message)
|
2020-08-14 10:02:13 +02:00
|
|
|
|
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
proc newIndexError*(message: string): ptr JAPLException =
|
|
|
|
result = allocateObj(JAPLException, ObjectTypes.EXCEPTION)
|
|
|
|
result.errName = newString("IndexError")
|
|
|
|
result.message = newString(message)
|
2020-08-15 11:27:04 +02:00
|
|
|
|
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
proc newReferenceError*(message: string): ptr JAPLException =
|
|
|
|
result = allocateObj(JAPLException, ObjectTypes.EXCEPTION)
|
|
|
|
result.errName = newString("ReferenceError")
|
|
|
|
result.message = newString(message)
|
2020-08-19 18:15:48 +02:00
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
|
|
|
|
proc newInterruptedError*(message: string): ptr JAPLException =
|
|
|
|
result = allocateObj(JAPLException, ObjectTypes.EXCEPTION)
|
|
|
|
result.errName = newString("InterruptedError")
|
|
|
|
result.message = newString(message)
|
2020-08-23 12:10:08 +02:00
|
|
|
|
2020-08-19 18:15:48 +02:00
|
|
|
|