Re: Initialize constants
- From: Hendrik Maryns <hendrik_maryns@xxxxxxxxxxxxx>
- Date: Fri, 14 Jul 2006 10:51:11 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Oliver Wong schreef:
"John Smith" <wleung7@xxxxxxxxx> wrote in message
news:1152826652.322835.187130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Oliver Wong wrote:
"John Smith" <wleung7@xxxxxxxxx> wrote in message
news:1152825768.284557.43280@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a Constants class and a Variable class.Exception {
I need to initialize a constant in the Constants class:
public static final String FILE_NAME;
The Variable class has a public String method that returns the full
pathway for the file name.
public String getVariable( String variableName ) throws Exception;
I have a getPath() method in Constants that calls getVariable in
Variable:
private static String getPath( String variableName ) throws
try {pick
Variable v = new Variable();
return v.getVariable( variableName );
}
catch ( Exception e )
{
throw e;
}
}
Now to initialize Constants.FILE_NAME, I need to call getPath() to
up the pathway.
If I do:
public static final String FILE_NAME = Constants.getPath( "PATH_NAME"
);
I got an "unhandled exception error".
If I wrap "public static final String FILE_NAME = Constants.getPath(
"PATH_NAME" );"
with a try-catch block as follows:
try {
public static final String FILENAME = Constants.getPath("PATH_NAME");
}
catch (Exception e){
throw e;
}
I got:
Syntax error, insert } to complete block
Syntax error on tokens, constructor ConstructorHeaderName expected
instead.
How do I go about initializing the value of FILE_NAME? I *must* use
Variable::getVariable().
Thanks for your help.
Make it so that private static String getPath( String variableName )
doesn't throw an exception. That means you'll have the handle the
exception
in a manner other than throwing it.
- Oliver
That would have been an easy solution; except I was explicitly told the
exceptions must be thrown up the stack until the "main program that
uses Constants".
Any other suggestions?
Hmm... How about wrapping the exception in a runtime exception
instead? E.g. throw new InvocationException(e);
I’d say this is going from bad to worse.
First of all, a class Constants does not seem a very good idea to me.
Neither does Variable (except if you mean some sort of representation
for a mathematical variable for it).
I’d say: rethink the design, and never ever throw Exception(). I.e.
alter the getVariable() method, then the problem melts away.
P.S. I am using google groups. How did you generate the
"news:1152825768.284557.43280@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"- Show quoted text -"
links in your reply?
I'm not using Google Groups. My newsreader does it automatically.
Uh, no, Google does that automatically.
H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEt1r/e+7xMGD3itQRAjFmAJ9ucg0a3OEoyYDizoN/lmIRSFGz4QCfW/5q
YIQ1PD1TId09+Au1PV2uwmc=
=cUPJ
-----END PGP SIGNATURE-----
.
- References:
- Initialize constants
- From: John Smith
- Re: Initialize constants
- From: Oliver Wong
- Re: Initialize constants
- From: John Smith
- Re: Initialize constants
- From: Oliver Wong
- Initialize constants
- Prev by Date: Re: JNLP on IE
- Next by Date: Re: eclipse 3.2 auto add import ?
- Previous by thread: Re: Initialize constants
- Next by thread: ant from command line returns java help syntax?
- Index(es):
Relevant Pages
|