• Post Reply Bookmark Topic Watch Topic
  • New Topic

Invocation Exception - please no!  RSS feed

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a little class that validates its constructor arguments and throws informative exceptions when it doesn't like them. My unit tests went nicely enough but now I'm building the thing with reflection by invoking the Constructor. The validation exceptions cause an invocation exception which is not informative at all. I'm betting there's no easy fix here, right?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InvocationTargetException.getCause() will give you the actual exception object that was thrown.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CotnractualJ mandates that all constructors throw UnsupportedOperationException always. It also mandates 100% code coverage during test. It follows then that it contains test cases that invoke these constructors with passing test cases. In fact, *every* test case contains this test.

Here is an excerpt of one:
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest, thanks! It just now occurred to me to look for such a thing but I hadn't gotten to it yet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!