sandwwraith
07/21/2026, 1:36 PMJson.decodeFromString can throw arbitrary IllegalArgumentException? For example, from init { require(x > 0) } blocks in serializable data classes. I'm asking this because there are a few requests to change that (https://github.com/Kotlin/kotlinx.serialization/issues/3111, https://github.com/Kotlin/kotlinx.serialization/issues/2165) that seem reasonable to me. But implementing them would mean that you cannot longer do catch(e: IllegalArgumentException) or catch(e: NumberFormatException), which is kinda incompatible behavior change. So far I'm thinking that augmenting exceptions this way will bring more good than harm; does anyone have arguments against?hfhbd
07/21/2026, 2:06 PMsandwwraith
07/21/2026, 2:26 PMcatch SerializationException and catch IllegalArgumentException now everything will go to the first onesandwwraith
07/21/2026, 2:26 PMcatch IllegalArgumentException because it has wider scope?hfhbd
07/21/2026, 2:27 PMOliver.O
07/21/2026, 3:40 PMBut implementing them would mean that you cannot longer doYou can, becausecatch(e: IllegalArgumentException)
SerializationException is a subclass of IllegalArgumentException, right?
The breaking change in this case would affect users which are now catching both, right?
orSo this would be the real breaking change, right? If my understanding is correct, I'd say the current way of differentiating between the above exceptions does not make a lot of sense, so breaking it is the reasonable way forward.,catch(e: NumberFormatException)
hfhbd
07/21/2026, 3:41 PMsandwwraith
07/22/2026, 10:06 AMor catch(e: NumberFormatException),
So this would be the real breaking change, right?Yes, this clause won't be triggered anymore.
catch(e: IllegalArgumentException) also won't be executed if you have more specific catch (e: SerializationException)pdvrieze
07/29/2026, 2:11 PMFilipp Zhinkin
10/06/2026, 4:59 PMSerializationException sub classes? MissingFieldException is one popular exception to catch. But is there a reason to catch other specific SerializationException s?
github.com/Kotlin/kotlinx.serialization/issues/3262 raises a fair question, but for serialization exceptions there might be more harm than good.CLOVIS
10/06/2026, 6:34 PMFor example, fromI absolute write code like that. However I never catch the related exception in business-critical code, only in logger/Ktor StatusPage stuff, which won't be problematic if the subclass slightly changesblocks in serializable data classes.init { require(x > 0) }