Announcement Announcement Module
No announcement yet.
Exceptions in init-method Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exceptions in init-method

    What happens when an init method throws an exception ?
    Suppose i have the following definition :
    <bean id="exampleInitBean" class="examples.ExampleBean" init-method="checkInitialization"/> and checkInitialization method throws an exception. At what point will this exception be caught and how will my application come to know about it.

  • #2
    You will get exception while loading the application context
    and your bean creation failed.

    You must handle ( write catch block ) to handle the exception and do not rethrow if you want to go ahead with bean creation if exception is ignorable.


    • #3
      If the exception is caught, then will the object creation proceed successfully ?


      • #4
        Yes. But objects state may be invalid it depends on your requirement.
        Thats why i wrote if that exception is imporant and must fix to have object in valid state and usable inspite of exception.