Exception Handling / Logging in Java Bean

classic Classic list List threaded Threaded
2 messages Options
Vikas Vikas
Reply | Threaded
Open this post in threaded view
|

Exception Handling / Logging in Java Bean

I have been asked to put a check on a particular field and then log a error if it fails the check. I am planning to add the check within setter of bean itself as i don't want to put it at various places that set this value.

Is it a good idea to handle exceptions , log errors within Beans which are just supposed to be carrier objects.
Jimmy Jimmy
Reply | Threaded
Open this post in threaded view
|

Re: Exception Handling / Logging in Java Bean

The only problem i could see is if It's serializable. You should be make the logger reference as  transient. Rest it shouldn't make any problem but still never seen and hence think its good not to keep logging inside bean. You can alternatively throw exception and catch in respective caller if that can be an alternative.