4 ms·
D has a feature which makes the compiler serialize the assert-ed expression into a format string so the runtime values can be printed contextually.
by mhh__ 4y ago
D has a feature which makes the compiler serialize the assert-ed expression into a format string so the runtime values can be printed contextually.
- mike_hearn 4y agoThis is usually called Power Assertions and other languages have them too. Groovy has it, and there's a compiler plugin for Kotlin that adds it. It's very useful and avoids the need to write assertion messages most of the time, whilst still letting you get useful outputs. The article seems to ignore all this, in fact, it argues other languages are even worse than C because assertion failures are exceptions. That seems dubious. In JVM languages assertions descend from a part of the exception hierarchy that normal software rarely catches, so they do tend to propagate to the top of the stack. Nonetheless, the ability to catch an assertion failure and do something with it is useful, because it lets you do things like crash reporting much easier. It also lets you build smaller in-process failure domains.
- telotortium 4y agoIs there a way to automatically break on exceptions in Java, or at least on AssertionError? It looks like it's possible in IntelliJ at least: https://stackoverflow.com/questions/23955273/can-intellij-idea-be-configured-to-break-when-a-junit-assertionerror-occurs https://stackoverflow.com/questions/23955273/can-intellij-id...
- mike_hearn 4y agoYes. You can break on all sorts of conditions. Breaking on any exception isn't all that useful though because lots of code throws and catches exceptions as part of its normal operations unfortunately.