Java: Can I Inject a runtime exception into an arbitrary class method at runtime?
<p>For testing purposes, at times I'd like to see how my code handles having an unexpected runtime exception thrown, from various parts of the code.</p>

<p>For example, say I have a method like so:</p>

<pre><code>public int getSum(int x, int y)
{
   return x + y;
}
</code></pre>

<p>Is there a way for me to cause this method to fail whenever it's called by throwing an exception instead of returning a valid result? I know I could add in explicit code to do this, but I'd like to know if it's possible to replace a method in <em>any</em> class with a new method that just throws an exception at runtime, or something like that ;-) Kind of like <a href="https://stackoverflow.com/a/15157021/26510">how Mockito can do the following</a>: </p>

<pre><code>doThrow(new Exception()).when(mockedObject).methodReturningVoid(...);
</code></pre>

<p>I'd prefer any solutions to not require any extra tools - just the standard JVM. Thanks!</p>