This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 243730

Summary: Surrounding statement with try-catch does not work
Product: java Reporter: Marcoevich
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: P3    
Version: 8.0   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:
Attachments: IDE log

Description Marcoevich 2014-04-10 13:02:42 UTC
Product Version = NetBeans IDE 8.0 (Build 201403101706)
Operating System = Windows 7 version 6.1 running on amd64
Java; VM; Vendor = 1.7.0_51
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.51-b03

Surround statement with try-catch adds incomplete and uncompilable try-catch block.

Suggestion add catch-clause does nothing
Comment 1 Marcoevich 2014-04-10 13:02:48 UTC
Created attachment 146670 [details]
IDE log
Comment 2 Marian Mirilovic 2014-04-17 16:04:13 UTC
Could you please attach the code before and after surrounding, and reopen this issue after ? Thanks in advance.
Comment 3 Marcoevich 2014-04-17 18:29:53 UTC
Hmm, I'am not sure if I can replicate the original bug. It looks like the command "surround statement with try-catch" works this time.

However, surround BLOCK with try-catch still acts a little weird.

In the following piece of code, if I surround the block with try-catch it'll look like this:

try {
            // TODO add your handling code here:
            
            int tafelNr = Integer.parseInt(tafelNrTxt.getText());
            ArrayList<String> rekeningRegels = m.geefRekening(tafelNr);
            
            //plak alle regels achter elkaar
            String rekeningRegelsString = "";
            for(String rekregel : rekeningRegels){
                rekeningRegelsString += rekregel;
            }
            
            //zet het in het rekeningveld
            rekeningTxt.setText(rekeningRegelsString);
       

    }  

As you see, there's no catch clause.

Netbeans will suggest adding a catch clause in this case, but clicking on that suggestion does nothing at all.
Comment 4 Svata Dedic 2014-08-05 19:08:23 UTC
(In reply to Marcoevich from comment #3)
> However, surround BLOCK with try-catch still acts a little weird.
> 
> In the following piece of code, if I surround the block with try-catch it'll

Works OK with 8.0.1; I've tried to surround the code sample (except the try {}) and NumberFormatException handler was generated.

Please attach a code sample before applying the "Surroung" suggestion, so I can test the exact code. Ideally attach the whole file. Thanks.