Question: I've faced an interesting aim, this aim targets the exception handling in existing web application written with wicket and hibernate frameworks, 
suppose we have web app which is deployed in server and sometimes it produces runtime exceptions, the problem is how to get and save their stacktrace to db without modifying all classes(about 80 models and 150 views).

Hope i gave all clear.  

Thanks in advance.

Answer: 
Wicket 1.4 and earlier
----------------------

Override [`Application.newRequestCycle()`](http://wicket.apache.org/apidocs/1.4/org/apache/wicket/Application.html#newRequestCycle%28org.apache.wicket.Request,%20org.apache.wicket.Response%29) and return a custom subclass of `WebRequestCycle` that overrides [`RequestCycle.logRuntimeException()`](http://wicket.apache.org/apidocs/1.4/org/apache/wicket/RequestCycle.html#logRuntimeException(java.lang.RuntimeException)) in order to provide additional logging behavior for all `RuntimeException`s in your application. Notice that any uncaught `Exception` will be wrapped by Wicket in a `WicketRuntimeException` (as stated in the *Exception handling* section of [Request cycle and request cycle processor](https://cwiki.apache.org/WICKET/request-cycle-and-request-cycle-processor.html)) :

There, use a Service/DAO component that will insert the exception message along with the stacktrace into the database. Remember that depending on the dbms, you might want to use a CLOB instead of a varchar type (for instance, in Oracle, a varchar column cannot hold more than 4000 bytes).

Here's an (*untested*) example: 

```
public class myApplication extends WebApplication { 
    ...
    @Override
    public RequestCycle newRequestCycle(Request request, Response response) {
        return new myRequestCycle(this, (WebRequest) request, (WebResponse) response);
    }
} 

public class myRequestCycle extends WebRequestCycle { 
    ...
    @Override
    protected void logRuntimeException(RuntimeException rex) {
        super.logRuntimeException(rex);
        Writer w = new StringWriter();
        t.printStackTrace(new PrintWriter(w));
        String stackTrace = w.toString();
        someService.logExceptionToDB(rex.getMessage(),stackTrace);
    } 
} 

```

Wicket 1.5 and later
--------------------

See [@Cristoph's answer](https://stackoverflow.com/a/12314525/851811)
Write a utility which uses StackTraceElement[] to give you the complete stacktrace. Use an implementation of OutputStream to push it to a CLOB object. (I don't think BLOB is needed)