News for hackers. Stuff that matters.
Re:Obscure C++ Features by kenrose on Wednesday December 11, 2013 @02:23AM (#6886381)
The function try blocks is new to me. It's actually kind of elegant (for C++). Granted, the reason I've probably never encountered it in the wild is that there are probably very few scenarios where you have a member in the initializer list where you want to handle an exception on initialization. If you were trying to handle an exception of an instance variable initializing, most people would just move that member to the constructor body (e.g., if you have a pointer). The only time this would be useful then is for members that don't have default initializers (e.g., a reference).
Re:Obscure C++ Features by jasonzemos on Wednesday December 11, 2013 @03:22AM (#6886557)
It's nice to avoid the default initialization and construct a member directly with the argument you want. Then you can construct a second member which might depend on that previous one, etc. This can even include lambdas right in the initialization list, and all of this may throw and log an error with the catch block. Personally, I rarely like to see code in the actual constructor body anymore.
Re:Obscure C++ Features by b-johansson on Wednesday December 11, 2013 @02:54AM (#6886464)
Function try blocks are also extra tricky because at the end of the catch block the exception is automatically rethrown. http://www.drdobbs.com/sutters-mill-constructor-failures-or-... has a lot of details on function try blocks.
Re:Obscure C++ Features by evincarofautumn on Wednesday December 11, 2013 @02:47AM (#6886442)
It also just removes a level of nesting, which is nice by itself.