Re: jdk 1.6 bug or feature?
"gg" wrote:
if I have declared
public class myArgException extends Exception{
Class names in Java should start with an upper-case letter. You've
heard this before, I'm willing to bet.
String sArgName = "",
sSz = "";
public myArgException (String argNm, String sz){
Why do you not follow the normal pattern of creating the standard
Exception constructors?
sArgName = argNm;
sSz = sz;
}
public @Override String getMessage (){
return "CPAStd005Header argument exception - =
Invalid length
for "
.concat(sArgName).concat(", must =
be ").concat(sSz)+"
characters "; }
This has a disadvantage of repeating the concatentation every time the
exception is asked to give up its message. While often this will only
be once, there are scenarios where an Exception is required to give up
its message more than once.
};
I can
public myMethod(String arg1, String arg2) throws myArgException {
if (some_conditionOfArg1) {
By convention, regular variable names should not contain underscores
but use camel case instead.
throw new myArgException ("arg1", 5"); //this i=
s OK
}
// on 2nd use, compiler rejects the new exception statement
if (some_conditionOfArg2) {
throw new myArgException ("arg2", "8"); //this =
is rejected by
compiler
Mystery to me. Did you literally copy and paste this code from your
buggy code? Why don't you supply us with an SSCCE, another concept
I'm willing to bet you've encountered in this newsgroup before?
Seriously, you should provide an SSCCE. I see nothing in your snippet
to account for the behavior you describe. Give us an SSCCE so we can
duplicate the error. Without an SSCCE it's much harder - those that
can create one for you will have to create one for you just to answer
your question. That hardly seems fair, to make someone else create an
SSCCE for you when you should have created the SSCCE. Don't you
agree?
I know I would find an SSCCE useful for me to try to help you.
// however it will take non anonymous throw;
myArgException e = new myArgException ("arg2", "8");
throw e;
}
}
If you provide an SSCCE, I will cheerfully run it and let you know
what I find out.
--
Lew
Gosh, I sure would like an SSCCE of your problem.