0

Mostly regarding Javascript, but there is some Java involved. I am using the Eclipse IDE and I have the following type of code in a .jsp file.

<%
//some stuff
try {
    //some java code
%>

<script type="text/javascript">
//Some javascript code to try

<% } catch(Exception e) {} %>

The issue is in the top portion of java, where it doesn't know that I later add in the catch(). I have an annoying error message showing up:

Multiple annotations found at this line:
     - Syntax error, insert "Finally" to complete TryStatement
     - Syntax error, insert "}" to complete ClassBody

While it has no effect on the compilation or actually causes any issues, I am curious if there is a way to suppress the warning so I don't have the red 'X' going up through all the folders?

It would be preferable if the solution did not affect the warnings in other files. I would give Imaginary Bonus Points for a solution which does not use Eclipse settings to handle the situation.

Solution: The reason the javascript code was in the try/catch was to keep it from running if an error was caught. Rather than doing it like above, it was reformatted like so:

<%
//some stuff
boolean valid = false;
try {
    //some java code
    valid = true;
} catch(Exception e) {} %>

<script type="text/javascript">
if (<%valid%>) {
//Some javascript code to try
}
DoubleDouble
  • 1,493
  • 10
  • 25
  • Maybe you are in the wrong perspective? Is there a JSP perspective? You may have to go to the JavaScript/Java setting in preferences and turn off some of the warnings. – Mr. Polywhirl Feb 24 '14 at 22:02
  • 1
    Are you being forced to write that kind of (Java) code in your JSP? http://stackoverflow.com/q/3177733/738746 – Bhesh Gurung Feb 24 '14 at 22:04
  • @Mr.Polywhirl I normally work in the `Java EE` perspective, but I tried looking through the `Javascript` perspective and don't notice any changes. – DoubleDouble Feb 24 '14 at 22:06
  • @BheshGurung To be honest, it is code a co-worker has put in, I assume he is forced to do so, but I do not really know. – DoubleDouble Feb 24 '14 at 22:10
  • 1
    Was he attempting to "catch" JavaScript exceptions or are there JSP evaluations within the try/catch block that could throw exceptions? – Matt Pileggi Feb 24 '14 at 22:12
  • @MattPileggi after some further investigation, he only wanted the javascript to run if the java code did not error. So rather than including the javascript code in the Try{} block we created a boolean for the javascript. Thanks for the good questions and references leading me to the answer everyone. – DoubleDouble Feb 24 '14 at 22:40
  • The Perspective has exactly nothing to do with this. Are you running the newest version the relevant plug-ins, Kepler SR1? – nitind Feb 24 '14 at 23:15
  • Suggestion: If you found the solution, post it as an answer to your own question and mark it as the correct answer. This will help others who find this issue through google and make it more clear what the solution is. – Fredrik Feb 25 '14 at 08:38

1 Answers1

0

Solution: The reason the javascript code was in the try/catch was to keep it from running if an error was caught. Rather than doing it like above, it was reformatted like so:

<%
//some stuff
boolean valid = false;
try {
    //some java code
    valid = true;
} catch(Exception e) {} %>

<script type="text/javascript">
if (<%=valid%>) {
//Some javascript code to try
}
DoubleDouble
  • 1,493
  • 10
  • 25