
Signature
Steve W. Jackson
Montgomery, Alabama
Hello,
What I probably need to do is throw an exception I guess. All I'm
trying to do is simply return a String value I can pass to another
method which will output to a jsp. I'm not sure how much more detail I
can use to explain it.
Thanks,
KP
> > Hello,
> > I am trying to output a String that I can pass to another method I
[quoted text clipped - 33 lines]
> Maybe you should be more explicit about what it is you need to do in
> order to get better feedback on how to do it right.
Oliver Wong - 07 Aug 2006 21:39 GMT
[post re-ordered]
>> > Hello,
>> > I am trying to output a String that I can pass to another method I
[quoted text clipped - 43 lines]
> Thanks,
> KP
AFAIK, this is the first time you mentioned "JSP", so that's already a
good start towards providing more information to a thorough solution. Read
http://riters.com/JINX/index.cgi/Suggestions_20for_20Asking_20Questions_20on_20N
ewsgroups
If you just want to learn about exceptions, see
http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
If you want some design advice, the problem with your current method is
that it's doing two different, but related things: It is determining whether
or not there is a problem, and if there is, it is generating an error
message explaining that problem. To fix it, you first have to determine
whether getting incorrect UPCs are a "normal" activity, or an "exceptional"
one. If it's normal, then just have your method check whether the UPC is
valid or not, and in your calling code, check the validity, and display an
error if it isn't valid, or continue normal processing if it is valid.
If the invalid UPC is exceptional, then forget about the checking
method; just proceed as if it were normal, and if you later on find out that
it wasn't valid, throw an exception.
- Oliver
sks - 07 Aug 2006 21:45 GMT
> Hello,
>
> What I probably need to do is throw an exception I guess. All I'm
> trying to do is simply return a String value I can pass to another
> method which will output to a jsp. I'm not sure how much more detail I
> can use to explain it.
You could throw and exception like IllegalUPCFormatException("Your string is
too long")
Moiristo - 08 Aug 2006 11:03 GMT
>> Hello,
>>
[quoted text clipped - 5 lines]
> You could throw and exception like IllegalUPCFormatException("Your string is
> too long")
I've used JSF for my webapp, and I created a class where I could store
validation errors in. So, instead of returning the error, I did:
'ViewUtils.addExceptionMessage("UPC error");'. When rendering the result
page, I could just look whether there were errors, and write them to the
screen if necessary. I think this could easily be implemented in JSP, too.