| try-catch [message #172328] | 
Mon, 09 August 2004 02:55   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
If I select a few statements and ask to surround them with try-catch, why do 
they always get wrapped with Excpetion and not the specific exceptions 
thrown in that block?
 |  
 |  
  | 
 | 
 | 
 | 
| Re: try-catch [message #172615 is a reply to message #172437] | 
Tue, 10 August 2004 03:49    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: hcs33.egon.gyaloglo.hu 
 
Hi, 
 
Yes, this can be a bit confusing. 
If you have a statement which can throw an Exception, invoking Quick-Fix 
(pressing Ctrl+1) shows an option 'Surround with try/catch' with a 'J!' 
icon. This is a shorthand for Source->Surround with try/catch block for one 
statement. 
 
When you select some code and invoke Quick-Fix you get a number of 'Surround 
with ...' options with a 'document' icon. Those are simply call the 
templates (Preferences->Java->Editor->Templates) which have the variable 
${line_selection} in their body. In this case you have to call the function 
from the Source menu. 
 
HTH, 
Regards, 
Csaba 
 
"Zohar" <david_fire4@hotmail.com> wrote in message 
news:cf81eh$b9i$1@eclipse.org... 
> DataOutputStream dos = new DataOutputStream(new ByteArrayOutputStream()); 
> String param = "ksksk"; 
> dos.write(param.length()); 
> dos.writeBytes(param); 
> 
> I select the 2 last statements. 
> CTRL+1 
> I select "Surround with 'try'(try catch block)" 
> I get a catch for Exception, and not IOException. 
> 
> If I use the Source->Surround with try/catch Block, then I get it right... 
> 
> 
> 
> "Andrea Spinelli" <aspinelli@no-spam-please-imteam.it> wrote in message 
> news:Xns954090290AF23aspinellinospampleas@204.138.98.10... 
> > "Zohar" <david_fire4@hotmail.com> wrote in 
> > news:cf771g$v8s$1@eclipse.org: 
> > 
> > > If I select a few statements and ask to surround them with try-catch, 
> > > why do they always get wrapped with Excpetion and not the specific 
> > > exceptions thrown in that block? 
> > 
> > test: 
> > 
> > import java.sql.PreparedStatement; 
> > 
> > ... 
> > 
> > PreparedStatement ps = null; 
> > ps.execute(); 
> > 
> > Now Eclipse highlights ps.execute(); 
> > 
> > Ctrl-1 and you obtain: 
> > 
> > PreparedStatement ps = null; 
> > try { 
> >                 ps.execute(); 
> >             } catch (SQLException e) { 
> >                 // TODO Auto-generated catch block 
> >                 e.printStackTrace(); 
> >             } 
> > 
> > SQLException is specific to the context. 
> > Please post an example of what you get wrong. 
> > 
> > HTH 
> >    Andrea 
> > 
> > 
> > -- 
> >   Andrea Spinelli - IT&T srl aspinelli@no-spam-plase-imteam.it 
> >   Via Sigismondi, 40 - 24018 Villa d'Alme' (BG) 
> >   tel: +39+035636029 - fax: +39+035638129 
> >   http://www.imteam.it/ 
> 
>
 |  
 |  
  | 
 | 
| Re: try-catch [message #173562 is a reply to message #172661] | 
Tue, 17 August 2004 06:43    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: daniel.megert.gmx.net 
 
Zohar wrote: 
 
>very unintuitive. 
>can this be fixed? 
>   
> 
Is there a bug report? No bug report - no fix. 
 
Dani 
 
>"Horváth, Csaba" <hcs33@egon.gyaloglo.hu> wrote in message 
>news:cf9uce$f6$1@eclipse.org... 
>   
> 
>>Hi, 
>> 
>>Yes, this can be a bit confusing. 
>>If you have a statement which can throw an Exception, invoking Quick-Fix 
>>(pressing Ctrl+1) shows an option 'Surround with try/catch' with a 'J!' 
>>icon. This is a shorthand for Source->Surround with try/catch block for 
>>     
>> 
>one 
>   
> 
>>statement. 
>> 
>>When you select some code and invoke Quick-Fix you get a number of 
>>     
>> 
>'Surround 
>   
> 
>>with ...' options with a 'document' icon. Those are simply call the 
>>templates (Preferences->Java->Editor->Templates) which have the variable 
>>${line_selection} in their body. In this case you have to call the 
>>     
>> 
>function 
>   
> 
>>from the Source menu. 
>> 
>>HTH, 
>>Regards, 
>>Csaba 
>> 
>>"Zohar" <david_fire4@hotmail.com> wrote in message 
>>news:cf81eh$b9i$1@eclipse.org... 
>>     
>> 
>>>DataOutputStream dos = new DataOutputStream(new 
>>>       
>>> 
>ByteArrayOutputStream()); 
>   
> 
>>>String param = "ksksk"; 
>>>dos.write(param.length()); 
>>>dos.writeBytes(param); 
>>> 
>>>I select the 2 last statements. 
>>>CTRL+1 
>>>I select "Surround with 'try'(try catch block)" 
>>>I get a catch for Exception, and not IOException. 
>>> 
>>>If I use the Source->Surround with try/catch Block, then I get it 
>>>       
>>> 
>right... 
>   
> 
>>> 
>>>"Andrea Spinelli" <aspinelli@no-spam-please-imteam.it> wrote in message 
>>>news:Xns954090290AF23aspinellinospampleas@204.138.98.10... 
>>>       
>>> 
>>>>"Zohar" <david_fire4@hotmail.com> wrote in 
>>>>news:cf771g$v8s$1@eclipse.org: 
>>>> 
>>>>         
>>>> 
>>>>>If I select a few statements and ask to surround them with 
>>>>>           
>>>>> 
>try-catch, 
>   
> 
>>>>>why do they always get wrapped with Excpetion and not the specific 
>>>>>exceptions thrown in that block? 
>>>>>           
>>>>> 
>>>>test: 
>>>> 
>>>>import java.sql.PreparedStatement; 
>>>> 
>>>>... 
>>>> 
>>>>PreparedStatement ps = null; 
>>>>ps.execute(); 
>>>> 
>>>>Now Eclipse highlights ps.execute(); 
>>>> 
>>>>Ctrl-1 and you obtain: 
>>>> 
>>>>PreparedStatement ps = null; 
>>>>try { 
>>>>                ps.execute(); 
>>>>            } catch (SQLException e) { 
>>>>                // TODO Auto-generated catch block 
>>>>                e.printStackTrace(); 
>>>>            } 
>>>> 
>>>>SQLException is specific to the context. 
>>>>Please post an example of what you get wrong. 
>>>> 
>>>>HTH 
>>>>   Andrea 
>>>> 
>>>> 
>>>>-- 
>>>>  Andrea Spinelli - IT&T srl aspinelli@no-spam-plase-imteam.it 
>>>>  Via Sigismondi, 40 - 24018 Villa d'Alme' (BG) 
>>>>  tel: +39+035636029 - fax: +39+035638129 
>>>>  http://www.imteam.it/ 
>>>>         
>>>> 
>>>       
>>> 
>>     
>> 
> 
> 
>   
>
 |  
 |  
  | 
 | 
Powered by 
FUDForum. Page generated in 0.09007 seconds