runtime: assertRuntimeError assertNegativeShift assertIndexRange

This commit is contained in:
visualfc
2024-05-17 21:13:42 +08:00
parent 307a1a295a
commit 03edb3bbbe

View File

@@ -8,8 +8,20 @@ func (e errorString) Error() string {
return "runtime error: " + string(e) return "runtime error: " + string(e)
} }
func CheckRuntimeError(b bool, s string) { func AssertRuntimeError(b bool, msg string) {
if b { if b {
panic(errorString(s).Error()) panic(errorString(msg).Error())
}
}
func AssertNegativeShift(b bool) {
if b {
panic(errorString("negative shift amount").Error())
}
}
func AssertIndexRange(b bool) {
if b {
panic(errorString("index out of range").Error())
} }
} }