Re: Catching Thrown Exceptions
Jukka Lahtinen wrote:
"Davej" writes:
"Davej" wrote:
I figured that if you threw an exception inside a try it would be
caught. No? In my Java program the throw was not caught. In C# this is
the way things work.
Ok, I apologize for not including specific details. This is a jsp file
and I had the following inside a try block...
if ( condition )
{
throw exception;
}
What the others said, and..
I can't see variables condition and exception defined anywhere.
Or a try block.
Or a catch block.
So, I guess the error must be on line 42. Or line 16514. Or somewhere
between, before, or after them.
Well, now, to be perfectly fair we do know certain things, even though the OP
has steadfastly refused to share a code example. We know he has Java code
inside a JSP. We know that he did *not* declare the variable 'exception'. We
know from the message
"org.apache.jasper.JasperException: Unable to compile class for JSP:
"An error occurred at line: 59 in the jsp file: /CalcLoan.jsp
exception cannot be resolved to a variable"
that the error is failure to declare 'exception', notwithstanding the OP's
refusal to believe the message's statement that it is a compilation error.
We know that he has Java source muddled in with the JSP. Yecch! (Shudder.)
Several respondents have pointed out the need for a 'catch' block to go with
the 'try'. It is time to recommend to the OP that they read both the Java SE
and Java EE tutorials, and to reiterate the suggestion that he study and
follow the advice in
http://sscce.org/
For the search-engine-challenged:
<http://www.oracle.com/technetwork/java/javase/documentation/index.html>
<http://www.oracle.com/technetwork/java/index-jsp-135888.html>
<http://www.oracle.com/technetwork/java/javaee/documentation/index.html>
<http://docs.oracle.com/javaee/6/tutorial/doc/>
Actually, scrap that one - they don't describe JSP any longer. For that:
<http://docs.oracle.com/javaee/5/tutorial/doc/bnagx.html>
"Davej" - measure twice, cut once, dude! Do some reading, learn first.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg