Introduce basic error handling

This commit is contained in:
2020-03-13 19:55:58 +01:00
parent 7eb543f2bc
commit a0a09ecb55
48 changed files with 534 additions and 263 deletions

View File

@@ -3,7 +3,7 @@ package io.smnp.ext.lang.method
import io.smnp.callable.method.Method
import io.smnp.callable.method.MethodDefinitionTool
import io.smnp.callable.signature.Signature.Companion.simple
import io.smnp.error.RuntimeException
import io.smnp.error.EvaluationException
import io.smnp.type.enumeration.DataType.INT
import io.smnp.type.enumeration.DataType.STRING
import io.smnp.type.matcher.Matcher.Companion.ofType
@@ -12,7 +12,7 @@ import io.smnp.type.model.Value
class CharAtMethod : Method(ofType(STRING),"charAt") {
override fun define(new: MethodDefinitionTool) {
new method simple(ofType(INT)) body { _, obj, (index) ->
Value.string((obj.value!! as String).getOrNull(index.value!! as Int)?.toString() ?: throw RuntimeException("Index '${index.value!!}' runs out of string bounds"))
Value.string((obj.value!! as String).getOrNull(index.value!! as Int)?.toString() ?: throw EvaluationException("Index '${index.value!!}' runs out of string bounds"))
}
}
}

View File

@@ -3,7 +3,7 @@ package io.smnp.ext.lang.method
import io.smnp.callable.method.Method
import io.smnp.callable.method.MethodDefinitionTool
import io.smnp.callable.signature.Signature.Companion.simple
import io.smnp.error.RuntimeException
import io.smnp.error.EvaluationException
import io.smnp.type.enumeration.DataType.INT
import io.smnp.type.enumeration.DataType.LIST
import io.smnp.type.matcher.Matcher.Companion.ofType
@@ -16,7 +16,7 @@ class ListAccessMethod : Method(ofType(LIST), "get") {
val i = index.value!! as Int
if(i >= list.size) {
throw RuntimeException("Index '$i' runs out of array bounds")
throw EvaluationException("Index '$i' runs out of array bounds")
}
list[i]

View File

@@ -3,7 +3,7 @@ package io.smnp.ext.lang.method
import io.smnp.callable.method.Method
import io.smnp.callable.method.MethodDefinitionTool
import io.smnp.callable.signature.Signature.Companion.simple
import io.smnp.error.RuntimeException
import io.smnp.error.EvaluationException
import io.smnp.type.enumeration.DataType.MAP
import io.smnp.type.matcher.Matcher.Companion.allTypes
import io.smnp.type.matcher.Matcher.Companion.ofType
@@ -13,7 +13,7 @@ class MapAccessMethod : Method(ofType(MAP), "get") {
override fun define(new: MethodDefinitionTool) {
new method simple(allTypes()) body { _, obj, (key) ->
val map = (obj.value!! as Map<Value, Value>)
map[key] ?: throw RuntimeException("Key '${key.value!!}' not found")
map[key] ?: throw EvaluationException("Key '${key.value!!}' not found")
}
}
}