To show error details like the stack trace, edit the web.config of your web application:
- Change <SafeMode CallStack="false" to <SafeMode CallStack="true"
- Change <customErrors mode="On" to <customErrors mode="Off"
Now you will see your full exceptions, no more "unexpected" or "undefined" SharePoint 2007 errors.