Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 5137721374801920: Issue #1173 - Default behavior for catch-all blocks

Created:
Feb. 25, 2015, 9:44 p.m. by Eric
Modified:
June 15, 2015, 7:29 a.m.
Reviewers:
sergei, Oleksandr
CC:
Felix Dahlke
Visibility:
Public.

Description

Issue #1173 - Default behavior for catch-all blocks Add template classes 'CatchAllVoid' and 'CatchAllReturn', which convert a template class argument containing separate handlers for each exceptions type into a single function that can be used as the entire body of a catch-all block. The engine that makes it go are the standard library functions 'current_exception' and 'rethrow_exception'. Add a function 'DefaultExceptionBehavior', defined with a set of trivial subhandlers implemented in class 'NullHandlers'. Sample usage: // ENTRY POINT try { // ... throw ... } catch (...) { DefaultExceptionBehavior(); }

Patch Set 1 #

Total comments: 4

Patch Set 2 : Remove extraneous file; fix spacing #

Patch Set 3 : add arguments for templates, add logging default function #

Total comments: 4

Patch Set 4 : rebase #

Patch Set 5 : Add ExceptionDefault() #

Total comments: 59

Patch Set 6 : Address comments #

Patch Set 7 : add 'const'; roll PluginErrorCodes.h into PluginDebug.h #

Total comments: 2

Patch Set 8 : rebase + nit #

Patch Set 9 : Changed entry point defaults in CPluginClass to match rebase #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+622 lines, -219 lines) Patch
M adblockplus.gyp View 1 2 3 4 5 6 3 chunks +3 lines, -1 line 0 comments Download
A src/plugin/Exception.h View 1 2 3 4 5 6 7 1 chunk +88 lines, -0 lines 4 comments Download
M src/plugin/PluginClass.cpp View 1 2 3 4 5 6 7 8 6 chunks +6 lines, -0 lines 0 comments Download
M src/plugin/PluginDebug.h View 1 2 3 4 5 6 7 3 chunks +60 lines, -0 lines 0 comments Download
M src/plugin/PluginDebug.cpp View 1 2 3 4 5 6 7 2 chunks +82 lines, -2 lines 0 comments Download
R src/plugin/PluginErrorCodes.h View 1 2 3 4 5 6 7 1 chunk +0 lines, -215 lines 0 comments Download
M src/plugin/PluginStdAfx.h View 1 2 3 4 5 6 1 chunk +0 lines, -1 line 0 comments Download
A test/plugin/ExceptionTest.cpp View 1 2 3 4 5 1 chunk +383 lines, -0 lines 0 comments Download

Messages

Total messages: 22
Eric
Review Notes -- I didn't actually define a useful default behavior yet. Probably that should ...
Feb. 25, 2015, 10:05 p.m. (2015-02-25 22:05:22 UTC) #1
Oleksandr
This looks really cleaver, of course, however I still don't understand why we keep focusing ...
Feb. 27, 2015, 10:48 a.m. (2015-02-27 10:48:35 UTC) #2
Eric
On 2015/02/27 10:48:35, Oleksandr wrote: > Even more, didn't we *just* agree that we should ...
Feb. 27, 2015, 3:17 p.m. (2015-02-27 15:17:40 UTC) #3
Eric
New patch set. http://codereview.adblockplus.org/5137721374801920/diff/5629499534213120/adblockplus.gyp File adblockplus.gyp (right): http://codereview.adblockplus.org/5137721374801920/diff/5629499534213120/adblockplus.gyp#newcode233 adblockplus.gyp:233: 'src/plugin/Exception.cpp', On 2015/02/27 10:48:36, Oleksandr wrote: ...
Feb. 27, 2015, 3:36 p.m. (2015-02-27 15:36:50 UTC) #4
Oleksandr
> I don't consider it refactoring. It's a way of implementing a default behavior > ...
March 1, 2015, 5:31 a.m. (2015-03-01 05:31:50 UTC) #5
Eric
New patch set. Added a function that's suitable for default behavior in system entry points: ...
March 2, 2015, 5:07 p.m. (2015-03-02 17:07:18 UTC) #6
Eric
On 2015/03/01 05:31:50, Oleksandr wrote: > My understanding of what we have agreed on is ...
March 2, 2015, 5:21 p.m. (2015-03-02 17:21:43 UTC) #7
Oleksandr
> They're necessary because you cannot log any data from an exception caught with > ...
March 4, 2015, 5:07 a.m. (2015-03-04 05:07:31 UTC) #8
Eric
On 2015/03/04 05:07:31, Oleksandr wrote: > I don't think the message from .what() will really ...
March 4, 2015, 3:19 p.m. (2015-03-04 15:19:23 UTC) #9
Oleksandr
Sorry, I have missed the last 2 patchsets in my previous comment. Patchset 3 does ...
March 5, 2015, 7:18 a.m. (2015-03-05 07:18:55 UTC) #10
Eric
Patch set 6 add ExceptionDefault() for exceptions caught outside of entry points. http://codereview.adblockplus.org/5137721374801920/diff/5733935958982656/src/plugin/PluginDebug.cpp File src/plugin/PluginDebug.cpp ...
March 5, 2015, 2:58 p.m. (2015-03-05 14:58:04 UTC) #11
Oleksandr
> Well, I would prefer to eliminate PluginErrorCodes.h and put all the definitions > here; ...
March 6, 2015, 4:02 a.m. (2015-03-06 04:02:52 UTC) #12
sergei
First of all, it looks really nice! However, I still hope will replace ``` try ...
March 6, 2015, 1:51 p.m. (2015-03-06 13:51:12 UTC) #13
Eric
New patch set addresses @sergei's comments. Current patch set is based of public tip. http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/adblockplus.gyp ...
March 6, 2015, 5:29 p.m. (2015-03-06 17:29:58 UTC) #14
Eric
On 2015/03/06 13:51:12, sergei wrote: > First of all, it looks really nice! Thank you. ...
March 6, 2015, 5:42 p.m. (2015-03-06 17:42:34 UTC) #15
Eric
New patch set 7. I rolled in all the definitions in PluginErrorCode.h that were actually ...
March 6, 2015, 6:12 p.m. (2015-03-06 18:12:57 UTC) #16
Oleksandr
One nit. LGTM otherwise. http://codereview.adblockplus.org/5137721374801920/diff/5730192894984192/src/plugin/Exception.h File src/plugin/Exception.h (right): http://codereview.adblockplus.org/5137721374801920/diff/5730192894984192/src/plugin/Exception.h#newcode58 src/plugin/Exception.h:58: static ReturnType Handler(T t=T()) Spaces ...
March 19, 2015, 2:02 p.m. (2015-03-19 14:02:43 UTC) #17
Eric
New patch set 7 is rebased, including the extensive modifications to 'CPluginClass'. The nit fix ...
March 20, 2015, 9:56 a.m. (2015-03-20 09:56:36 UTC) #18
sergei
I've played a bit with the code in tests, one can find it here http://codereview.adblockplus.org/5743529531801600/ ...
March 31, 2015, 2:30 p.m. (2015-03-31 14:30:51 UTC) #19
Eric
On 2015/03/31 14:30:51, sergei wrote: > It's not necessary to have unique names, otherwise it ...
May 14, 2015, 2:38 p.m. (2015-05-14 14:38:51 UTC) #20
Eric
I made no code changes based on the latest round of comments. No new patch ...
May 14, 2015, 2:42 p.m. (2015-05-14 14:42:50 UTC) #21
sergei
May 15, 2015, 1:13 p.m. (2015-05-15 13:13:24 UTC) #22
http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/src/...
File src/plugin/Exception.h (right):

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/src/...
src/plugin/Exception.h:25: static void Handler(T t=T())
On 2015/05/14 14:42:50, Eric wrote:
> It doesn't introduce a requirement unless you leave out the argument.
Without default argument value one cannot leave out the argument because
compiler will tell about it.

> On 2015/03/31 14:30:51, sergei wrote:
> Using a parameter here is a work-around for the lack of variadic templates in
> the version of MS VC++ we're using, as was adequately documented elsewhere in
> the patch set. The most analogous substitute is to allow 0 or 1 argument.
> 

Default constructible argument and variadic templates are different things. For
example, it does not compile when T is a reference to an interface.

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/src/...
File src/plugin/PluginDebug.cpp (right):

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/src/...
src/plugin/PluginDebug.cpp:79: // VS 2012 does not have support for brace
initializer lists; otherwise this could be a single line
On 2015/05/14 14:42:50, Eric wrote:
> On 2015/03/31 14:30:51, sergei wrote:
> > Anyway, I would remove these comments regarding variadic templates because
> they
> > don't explain anything specific in the logic here.
> 
> The comments about variadic templates stay. It's indicating how to change the
> code when we upgrade compiler versions.
> 
> The code will be simpler, not more complicated, with variadic templates,
because
> all the arguments become pass-through arguments.

There are another more reliable technics how to find all places which should be
changed, this comment looks redundant here.

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/test...
File test/plugin/ExceptionTest.cpp (right):

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/test...
test/plugin/ExceptionTest.cpp:134: enum ExceptionCode
On 2015/05/14 14:42:50, Eric wrote:
> On 2015/03/31 14:30:51, sergei wrote:
> > it helps to understand the logic here 
> 
> I don't agree with you. It provides nothing extra.
If you does see it now it does not mean that it provides nothing extra.

> 
> > In my changes I've made them scoped and there is no trouble with it.
> 
> I never said it couldn't work. I said it was unnecessary and extraneous.
> 
> If you'd like to change it, you can suggest your changes after the current
> change set is committed.
Sure, I can, but why not to do it better at the first round?

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/test...
test/plugin/ExceptionTest.cpp:146: typedef int return_t;
On 2015/05/14 14:42:50, Eric wrote:
> On 2015/03/31 14:30:51, sergei wrote:
> > `typedef ExceptionCode return_t;` reflects better what we expect to have
> > as a return type here than int. 
> 
> Defining a typedef for the symbol 'return_t' reflects exactly that we are
> expecting a return type. If that were not the expectation I would have just
> declared them returning 'int' in the first place. It adds nothing to insist on
a
> second level of symbolic indirection by defining 'ExceptionCode'. It's
_already_
> defined as a return type. Indeed, it's less general to indicate that the
return
> type is supposed to be an exception code; it need not be at all (although
that's
> the way we'll be using it).

I really don't understand attempts to create less robust code by avoiding
assistance from the compiler and to write less self describing code.

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/test...
test/plugin/ExceptionTest.cpp:199: void SimpleVoid(X x, H h)
On 2015/05/14 14:42:50, Eric wrote:
> On 2015/03/31 14:30:51, sergei wrote:
> > I've also changed it and there is no issue with it.
> 
> I picked a different syntax that the one you would have picked. I picked the
one
> that used type inference, which means that you instantiate a dummy variable.
It
> works.
> 
> Using an explicit template argument also works. I never said it wouldn't. I
> prefer using a dummy instantiation.
> 

So, how does it simplify?

http://codereview.adblockplus.org/5137721374801920/diff/5759778777202688/test...
test/plugin/ExceptionTest.cpp:203: if (SimpleExpected == 0) { SimpleExpected =
1; }
On 2015/05/14 14:42:50, Eric wrote:
> On 2015/03/31 14:30:51, sergei wrote:
> > Sorry, I don't understand what kind of references are mentioned here. 
> 
> The word 'reference' can mean either its generic English meaning or a specific
> C++ primitive type. I am using it here in its generic sense.
> 
> > Randomness
> > is definitely overhead here.
> > I've tried to get rid of these global variables and it seems there is no any
> > trouble with it.
> 
> Of course you can get rid of the randomness. I don't think I claimed
otherwise.
> It's there, however, to substitute for local scope. If you get rid of the
nonce,
> you lose an element of the integrity check.
> 

Such randomness here does not add any integrity check here, it only complicates
the logic and distracts from the main logic.

http://codereview.adblockplus.org/5137721374801920/diff/5635415851663360/src/...
File src/plugin/Exception.h (right):

http://codereview.adblockplus.org/5137721374801920/diff/5635415851663360/src/...
src/plugin/Exception.h:31: catch (std::system_error& ex)
On 2015/05/14 14:42:50, Eric wrote:
> On 2015/03/31 14:30:51, sergei wrote:
> > We don't need non const references, so it is better to add const modifier to
> all
> > exceptions
> 
> Using 'const' here is overly restrictive. It requires the 'SubHandlers'
members
> to all be declared 'const'. There's no need to enforce it here in the
template.

Yes, it's more restrictive and requires `SubHandlers` members to have exception
argument as a const reference (it's different from your version). It saves us
from any kind of mistakes at the compile time. If we ever need non-const
reference to exception in some new `SubHandlers` then we can remove `const` here
and continue to use old `SubHandlers`.
Can someone tell when we need non-const reference to the exception?

Powered by Google App Engine
This is Rietveld