Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can not solve my problem....

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
I want to validate my description through my servlet as well not just client side with javascript so for exapmle if you enter single code it should reload the template and gives you this error message that this description is not valid and please re-enter as you can see in my servlet but the problem it my catch part has error and it says:
please help me how can I solve this problem.
Many thanks,
Elahe
WEB-INF/classes/com/srs/bugtrack/BugDesc.java [150:1] Exception org.apache.velocity.exception.ResourceNotFoundException thrown from getTemplate must be caught, or it must be declared in the throws clause of this method
templateRet = getTemplate("BugDescription.html");
^
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That error is telling you that you must enclose that getTemplate() call in another try{}catch{} structure because it throws a checked exception.
Bill
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William could you please describe more?... still I didn't get it and what should I do?
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to catch the exception 'org.apache.velocity.exception.ResourceNotFoundException' inside this catch block:

Rene
[ July 30, 2002: Message edited by: Rene Larsen ]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using Velocity, you must catch a few types of exception when using getTemplate():When I was trying to understand them all, I coded the above. In short, there are two major things that *could* go wrong when calling a Velocity template.

1) The template itself contains velocity macro errors (parsing error, the first listed above)

2) The template cannot be found (you named it/called it incorrectly, that template is just NOT on the file system, the second one listed)

3) Generic exception to catch anything else.
[ July 30, 2002: Message edited by: Mike Curwen ]
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends,
I made some changes and moved the try and catch block right after the fldDesc to validate it but still I have one error that says:
Exception java.sql.SQLException is never thrown in the body of the corresponding try statement.
catch ( SQLException x ) {
^
1 error
How can I solve this? Your Help is highly appreciated
Elahe
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear mike,
I have done these in abstract class that calls BaseServlet so now based on this so now based on and as I told that I moved that try and catch block right after fldDesc and how can I deal with with that error?
Many thanks,
Elahe
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,
I found this in JavaRanch old email:
"This error comes when u r unnecessarily catching an exception. so it seems that throughout ur try block u r not using any function/statement that throws SQLException and still u r catching it. that's why compiler is complaining."
So in that case how can I deal with this since I want to validate my text first right after getting the description form template. I will copy my code one more time...
Many thanks,
Elham
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it is better if I ask you guys give me the best idea to solve this issue.
Elahe
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the compiler says you are trying to catch an exception that won't be thrown by anything in the try block. So get rid of the
catch(SQLException)
{
.
.
.
}
and replace it with catch blocks for any exceptions that can be thrown. If nothing in the try block throws an exception then you should get rid of it, too.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But John when I enter the single code ' in my template where it asks for description, it thowns a SQL Exception, so I have to catch this error, so I need this block in my code and I am totally confused where should I put this ?
Please Please help me I have to fonish it today
Please let me know if I have to clear it more...
Many thanks,
Elahe
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your original problem was that the statement:
templateRet = getTemplate() ;
was NOT INSIDE A TRY BLOCK! The compiler knew that the statement could throw a checked exception, thats why you got the message.
The statement was INSIDE A CATCH BLOCK! Not the same thing as being inside a try block. You can have a try block inside a catch block - happens all the time.
try {
templateRet = getTemplate("BugDescription.html");
}catch(Exception xxx ){
System.out.println( xxx.toString() );
}
should work.
Bill
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill you are great! it works!!!
Thank you sooooooooooooooooo much
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!