title: Forging a stack trace in Java
body: <p>When you use RMI in Java the remote stack trace of an exception will be prepended when you receive it, somewhat like this:</p>
  
  <pre><code>ERROR Client received error when doing stuff:
  myapp.FooBarException: bla
   at server.myMethod()
   at rmi.callHandler() // and now, on the next line comes the client
   at rmi.sendCall();
   at client.doServerMethod()
   at Thread.run()
  </code></pre>
  
  <p>How is that kind of stacktrace "forgery" done?</p>
  
  <hr>
  
  <p>What do I want it for (apart from just being iterested)? Well, it would help me if I could do this:</p>
  
  <pre><code>outer() {
  
    thread = new Thread(...
        inner();
        // inner() throws
        // RuntimeException
        //  at inner();
        //  at Runnable.run();
        //  at Thread.run();
        //  at outer();
        //  at lalalala();
        //  ...
  
    ).start();
  
    thread.join();
  
  }
  </code></pre>
  
  <p>And make it so that an exception thrown in <code>inner()</code> would have <code>outer()</code> (and methods lower down the chain) in the stacktrace as well, for logging purposes.</p>