Bug 571208 - Evaluation error when using try-catch in the snippet
Summary: Evaluation error when using try-catch in the snippet
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.19   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 571220
  Show dependency tree
 
Reported: 2021-02-15 09:38 EST by Gayan Perera CLA
Modified: 2023-02-20 16:30 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gayan Perera CLA 2021-02-15 09:38:53 EST
try{
  return 10;
}
catch (Exception e) {
  e.printStackTrace();
}


Ends up with the following error
	Evaluation failed. Reason(s):
		Syntax error, insert ";" to complete BlockStatements



Using this 
try{
  return 10;
}
catch (Exception e) {
}

will ends up in 
	Evaluation failed. Reason(s):
		Syntax error on token "return", delete this token
Comment 1 Gayan Perera CLA 2021-02-15 09:40:01 EST
I will have look at this bug for next release if current release is too late.
Comment 2 Gayan Perera CLA 2021-02-15 14:36:56 EST
The main issue is https://bugs.eclipse.org/bugs/show_bug.cgi?id=571219, if we fixed this issue i don't see a real need for try-catch. But i will keep the issue open in case someone can point of a good use case.
Comment 3 Sarika Sinha CLA 2021-02-16 02:38:39 EST
(In reply to Gayan Perera from comment #2)
> The main issue is https://bugs.eclipse.org/bugs/show_bug.cgi?id=571219, if
> we fixed this issue i don't see a real need for try-catch. But i will keep
> the issue open in case someone can point of a good use case.

I am not sure if the reason is this.


The error what we are getting here is when JDT Core parses this code unit.
Comment 4 Gayan Perera CLA 2021-02-16 04:05:51 EST
I tried it and seems like its not parsing only. We don’t have support for instructions as well.
Comment 5 Sarika Sinha CLA 2021-02-16 05:26:08 EST
(In reply to Gayan Perera from comment #4)
> I tried it and seems like its not parsing only. We don’t have support for
> instructions as well.

what do you mean by not parsing only? 
I observe that CompilationUnit created comes with  2 problems in org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine.parseCompilationUnit(char[], String, IJavaProject, Map<String, String>)
Comment 6 Gayan Perera CLA 2021-02-16 05:29:19 EST
Yes there is parsing issue at that place as well. But for some reason when i wrote a test for this, it actually got parsed and when into AST visitor which construct instructions. And for try catch we throw out saying we don’t support at visiting phase.
Comment 7 Sarika Sinha CLA 2021-02-20 01:43:52 EST
After the new patch you can see we get this error:
Try statement cannot be used in an evaluation expression

https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/176435/5
Comment 8 Eclipse Genie CLA 2023-02-20 16:30:27 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.