I have a situation where I need to capture method arguments and its values whenever an exception is generated. I checked the Exception and Throwable classes but they don't hold any information about the method parameters.
If the specific subclass of Throwable stored the arguments in its fields, you can introspect (using Reflection) the Throwable object to see what fields and methods it has that might represent those arguments. That's if they're not private, of course.
The JavaBeans API might help in finding JavaBeans-compatible getter methods.
If the Throwable object has not stored the arguments anywhere, or encoded them into the message string, there is no way to retrieve them.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I was thinking of something like this:-More tedious, but simple and you don't have to mess about with reflection. I think I have got the two arguments the right way round. When you catch the new Exception you can get the original Exception from it and get its stack trace to find where it occurred.
My problem is some what tricky, I have to log details (including parameter passed) for every exceptions generated by the application. I was thinking of minimizing the changes in order to set this up, but it seems there is no easy way other then making wholesome changes in order to capture method parameters.
Well, one approach would be to use something like AspectJ at compile time, to insert bytecode at every exception constructor to take the string message argument and append a listing of the current method parameters just before the constructor is invoked. It would take some time to learn how to use AspectJ for this, but once you've done that it should require no modification of the rest of the code.