#Opinion on Default Exception Handling
1 messages ยท Page 1 of 1 (latest)
not fully sure what u mean. throw an exception when u think its time to throw an exception. doesnt matter if this is in a switch or not
๐
maybe u can clarify or show an example
An example
Like this do you prefer to add one more "case" and don't add the default at all
u need the default
the switch should be exhaustive
either add a case for all options or add a default case
๐
there is nothing wrong with throwing in default, thats very common
๐
The general rule is that exceptions are for programmer errors
So if the default can't happen unless you extend an enum, or don't properly validate the input, throw an UnsupportedOperationException
That's my preferred one, as in "I get it, but I don't support it"
(or also AssertionError if you consider this to be impossible based on how the code is written)
Random sidenote: wonder if not having -ea enabled suppresses AssertionError or it just disables assert statements
just the latter
โค๏ธ