Hi,
This question is a pretty trivial one. But I am looking for a best practice available. In our EJB application, exceptions are caught at different places - in EJB, Facades and in struts action classes. In all the places, we throw application specific exceptions with meaningful messages. Now, my question is,
1.how to avoid hardcoding of these exception messages?
2.is it good to read it through a properties file or have it as Gloabls public static final variables.
TIA
sgt.pepper
-
How to avoid hardcoding of exception messages (3 messages)
- Posted by: sgt pepper
- Posted on: November 07 2003 12:02 EST
Threaded Messages (3)
- ResourceBundle? by Sean Sullivan on November 07 2003 12:59 EST
- Re: How to avoid hardcoding of exception messages by Tom Cole on November 07 2003 13:26 EST
- Re: How to avoid hardcoding of exception messages by sgt pepper on November 07 2003 17:55 EST
-
ResourceBundle?[ Go to top ]
- Posted by: Sean Sullivan
- Posted on: November 07 2003 12:59 EST
- in response to sgt pepper
Can you provide more information?
Are you thinking about localizing the exception messages?
Have you considered using a ResourceBundle? -
Re: How to avoid hardcoding of exception messages[ Go to top ]
- Posted by: Tom Cole
- Posted on: November 07 2003 13:26 EST
- in response to sgt pepper
One would assume that you want to avoid hard coding because you either:
a) want to be able to change them without recompiling (killing your Global public static final variable idea), or
b) want to assign a common message to a large number of exceptions without keying each one in. This would adapt to either of your ideas.
I would say, store them in an XML file and read them once during startup into some sort of ExceptionFactory. Then dispense at will. This way you can change them without recompilation, though you will have to re-initialize (restart the server(s)) them. -
Re: How to avoid hardcoding of exception messages[ Go to top ]
- Posted by: sgt pepper
- Posted on: November 07 2003 17:55 EST
- in response to Tom Cole
Guys thanks for the comments.
1) Idea is to reuse message ( localization in long run )
2) is nt the XML approach a bit complex for a task as this? whats the harm in using a .properties?