Why not use something that doesn't forget to work, and is easier to read? For example:
X& do_something(int x) { if (x >= 3) throw("FAIL"); return *this; }
I am not an expert on compilers, but I think the example you posted will work if the compiler handles this particular case of an angle. As I read this, your do_something(int x) function expands to this:
X& do_something(int x) { if x < 3 return *this; else return throw("FAIL"); }
Now throw is a keyword and, as such, has no return value, therefore, strictly speaking, this is a compile-time error. However, I think the compilers (or at least some of them) are kind enough to go: "Oh, good ... There is no return value, but throw is a special situation that will cause the function to not return anyway, so donβt let complain and let the exception handling at runtime. "
I personally do not like to take my chances with compilers and try to keep everything as good as possible, but ... although this may be the best practice, it can also be just a personal preference.
Nickey
source share