3 ms·
Mostly there is no need for "ThisShouldNeverHappenException" since java has a IllegalStateException
by merb 11y ago
Mostly there is no need for "ThisShouldNeverHappenException" since java has a IllegalStateException
- stillworks 11y agoBut,but... ThisShouldNeverHappenException, NEVER ? What were they smoking.
- manyxcxi 11y agoTo be fair, someone writing a ThisShouldNeverHappenException may not be the kind of developer that knows about an IllegalStateException.
- merb 11y agoActually they at least need to know about a RuntimeException then. So that would've worked, too: throw new RuntimeException("This should never happen!"); There would've been a difference between a Exception and a RuntimeException. Also sometimes this kind of RuntimeException happens when you convert one type into another and want to explictly call all cases something like that: interface A class AA implements A class AB implements A if (x instanceof AA) {} else if (x instanceof AB) {} else { throw new IllegalStateException; } It's sometimes better to explicitly call all states instead of using the last else for the AB branch, since sometimes this will be extended later or the compiler would've throw an error since you have a return inside the if or else if. Btw. Kotlin and Scala won't have this problem due to pattern matching.