perf: make exception an object

This commit is contained in:
Sculas 2022-09-06 22:35:33 +02:00
parent d6308e126c
commit 75d2be8803
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89

View File

@ -11,7 +11,7 @@ class IllegalValueException(val value: Any?) : Exception("Illegal value: $value"
class InvalidTypeException(val got: String, val expected: String) : class InvalidTypeException(val got: String, val expected: String) :
Exception("Invalid option value type: $got, expected $expected") Exception("Invalid option value type: $got, expected $expected")
class RequirementNotMetException : Exception("null was passed into an option that requires a value") object RequirementNotMetException : Exception("null was passed into an option that requires a value")
/** /**
* A registry for an array of [PatchOption]s. * A registry for an array of [PatchOption]s.
@ -79,7 +79,7 @@ sealed class PatchOption<T>(
var value: T? = default var value: T? = default
set(value) { set(value) {
if (value == null && required) { if (value == null && required) {
throw RequirementNotMetException() throw RequirementNotMetException
} }
if (!validator(value)) { if (!validator(value)) {
throw IllegalValueException(value) throw IllegalValueException(value)