java - logging and wrapping exceptions. is this good practice? -


do think it's worth wrap service methods in try catch block log exceptions this:

public void attachclean(car instance) {     log.info("attaching clean car instance");     try {         getsessionfactory().getcurrentsession().lock(instance, lockmode.none);         log.info("attach successful");     } catch (runtimeexception re) {         log.error("attach failed", re);         throw re;     } } 

it seems lot of typing

you log or rethrow, not both. upper layers may able handle exceptional state, , logging entire stacktrace unnecessary in such case. hovewer, if absolutely want make sure it's logged, can log on own. logging exception multiple times better missing important exception in log file.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -