2020-10-21 22:49:08 +02:00
|
|
|
# Copyright 2020 Mattia Giambirtone
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2020-10-21 22:34:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Defines JAPL exceptions
|
|
|
|
|
2020-10-25 12:45:03 +01:00
|
|
|
import jstring
|
|
|
|
import jobject
|
2020-08-23 23:48:38 +02:00
|
|
|
import strformat
|
2020-08-10 18:39:53 +02:00
|
|
|
|
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
proc stringify*(self: ptr JAPLException): string =
|
2020-09-03 19:24:18 +02:00
|
|
|
return &"{self.errName.stringify}: {self.message.stringify}"
|
2020-08-23 23:48:38 +02:00
|
|
|
|
2020-10-23 17:14:55 +02:00
|
|
|
proc isFalsey*(self: ptr JAPLException): bool =
|
|
|
|
return false
|
2020-08-14 10:02:13 +02:00
|
|
|
|
2020-08-26 11:41:39 +02:00
|
|
|
proc newTypeError*(message: string): ptr JAPLException =
|
2020-10-17 15:26:57 +02:00
|
|
|
result = allocateObj(JAPLException, ObjectType.Exception)
|
2020-08-26 11:41:39 +02:00
|
|
|
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 =
|
2020-10-17 15:26:57 +02:00
|
|
|
result = allocateObj(JAPLException, ObjectType.Exception)
|
2020-08-26 11:41:39 +02:00
|
|
|
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 =
|
2020-10-17 15:26:57 +02:00
|
|
|
result = allocateObj(JAPLException, ObjectType.Exception)
|
2020-08-26 11:41:39 +02:00
|
|
|
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 =
|
2020-10-17 15:26:57 +02:00
|
|
|
result = allocateObj(JAPLException, ObjectType.Exception)
|
2020-08-26 11:41:39 +02:00
|
|
|
result.errName = newString("InterruptedError")
|
|
|
|
result.message = newString(message)
|
2020-08-23 12:10:08 +02:00
|
|
|
|
2020-08-19 18:15:48 +02:00
|
|
|
|
2020-09-01 18:09:36 +02:00
|
|
|
proc newRecursionError*(message: string): ptr JAPLException =
|
2020-10-17 15:26:57 +02:00
|
|
|
result = allocateObj(JAPLException, ObjectType.Exception)
|
2020-09-01 18:09:36 +02:00
|
|
|
result.errName = newString("RecursionError")
|
|
|
|
result.message = newString(message)
|
|
|
|
|