-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced exception handling for BeanExceptions in AnnotationBeanFactory #31
Enhanced exception handling for BeanExceptions in AnnotationBeanFactory #31
Conversation
To discuss: Maybe we should pass the original exception to the BeanException and not just the exception message? Because now we loose the filename and line number where the original exception occurred. In some cases this could make the debugging quite complicated, I assume. What do you think? |
I recently tested your suggestion and I'm struggling right now between having the exception and its trace as message by using:
which gives a nice representation of the previous exception probably even without using XDebug
and
which is imho the technically correct approach but gives you only a nice trace if using XDebug:
When using the first approach we would lose the possibility to traverse the exception stack via $e->getPrevious(), which may cause other problems when using logging libraries etc. and that is why I prefer the second approach. |
Sounds good to me. Thanks. Can you make the needed change to the PR please? |
The second approach has already been implemented in this pull request to achieve the goal described above. |
…nfactory_exception Enhanced exception handling for BeanExceptions in AnnotationBeanFactory
I recently ran into a problem concerning the exception handling while instanciating a bean.
If you write or use a class, which throws an exception during the constructor call, I get the following when trying to instanciate the bean by calling $beanFactory->get('myClass') for a CLI application:
what hides any information about the original exception and makes it difficult to debug.
In my case the error message was "Make sure you are passing in the correct parameters" which also could be an error of my bean configuration as well (wrong reference inside a @parameter annotation).
If the original exception is passed as previous for the BeanException, we will see the correct stack trace (at least when using XDebug).