Ellen Spertus
11/07/2022, 2:42 PMrequire()
a function rather than a string?
I can think of two possible answers:
1. In case constructing the message is expensive (seems unlikely).
2. In case we want to do additional processing before throwing the exception, such as logging or cleaning up.
I'm teaching about Kotlin exceptions, so I really want to get this right.Chris Lee
11/07/2022, 2:43 PMJoffrey
11/07/2022, 2:43 PM1. In case constructing the message is expensive (seems unlikely).Why would that be unllikely? String concatenation with arbitrary
toString()
isn't exactly cheap, so if you're using it in performance-sensitive code, it may be important to not construct the message if it's not usedKevin Del Castillo
11/07/2022, 2:45 PMVampire
11/07/2022, 3:07 PMrequire("foo")
vs. require { "foo" }
Ellen Spertus
11/07/2022, 3:49 PMChris Lee
11/07/2022, 3:50 PMrequire
to alter state, cleanup, etc.Kevin Del Castillo
11/07/2022, 3:51 PMrequire
should be a pure function, no side effectsJoffrey
11/07/2022, 3:53 PMif
statement and throw IAE manuallyKevin Del Castillo
11/07/2022, 3:59 PMJoffrey
11/07/2022, 4:01 PMKevin Del Castillo
11/07/2022, 4:04 PMrequire
should only be concerned to return the error messageJoffrey
11/07/2022, 4:05 PMEllen Spertus
11/07/2022, 4:06 PM