2020-10-21 22:34:04 +02:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
# to you 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.
|
|
|
|
|
|
|
|
|
|
|
|
## Defines JAPL exceptions
|
|
|
|
|
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 =
|
2020-09-03 19:24:18 +02:00
|
|
|
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 =
|
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)
|
|
|
|
|