Results 1 to 4 of 4

Thread: Exceptions in init-method

  1. #1
    Join Date
    Apr 2009
    Posts
    10

    Default 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. #2
    Join Date
    Dec 2009
    Location
    Pune,India
    Posts
    60

    Default

    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. #3
    Join Date
    Apr 2009
    Posts
    10

    Default

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

  4. #4
    Join Date
    Dec 2009
    Location
    Pune,India
    Posts
    60

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •