Asserts should not make the function return #13111
Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
In my opinion, your expectations in this case are not in line with the generally accepted standards. As far as I know and can judge from the Wikipedia article, in most languages, failure to meet the
I think it is perfectly fine to create a custom error checking method if none of the built-in methods suit your needs. Note, however, that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently,
assert()
generates an error when failed. While not stated in the documentation, this causes the currently executing function to returnnull
at the assert which creates two issues:This makes
assert()
unsuitable for its intended purpose: catching unexpected states during debugging without altering runtime logic. The current workarounds are as follows:push_warning()
. This logs a warning without returning from the function, but it does not halt execution in the debugging environment.push_error()
. This logs an error and halts execution, and it is consistent between debug and release builds, but it still returns from the function.push_warning()
combined withbreakpoint
. This achieves the desired effect, but having to write two lines each time you want this effect is not ideal.assert()
in a wrapper function. This also achieves the desired effect by only returning in the wrapper function, but the programmer should not have to define their own function.My proposal is to make
assert()
behave similarly to combiningpush_warning()
andbreakpoint
.Beta Was this translation helpful? Give feedback.
All reactions