Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » try-catch
try-catch [message #172328] Mon, 09 August 2004 02:55 Go to next message
Eclipse UserFriend
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 #172343 is a reply to message #172328] Mon, 09 August 2004 03:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.news.gmx.net

"Zohar" <david_fire4@hotmail.com> schrieb im Newsbeitrag
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?
>

Maybe one of those statements throws Exception? If there are no
exceptions then typically RuntimeException is choosen.

Regards

robert
Re: try-catch [message #172400 is a reply to message #172328] Mon, 09 August 2004 08:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aspinelli.no-spam-please-imteam.it

"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 #172437 is a reply to message #172400] Mon, 09 August 2004 10:25 Go to previous messageGo to next message
Eclipse UserFriend
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 #172615 is a reply to message #172437] Tue, 10 August 2004 03:49 Go to previous messageGo to next message
Eclipse UserFriend
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 #172661 is a reply to message #172615] Tue, 10 August 2004 09:35 Go to previous messageGo to next message
Eclipse UserFriend
very unintuitive.
can this be fixed?

"Horv
Re: try-catch [message #173562 is a reply to message #172661] Tue, 17 August 2004 06:43 Go to previous messageGo to next message
Eclipse UserFriend
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/
>>>>
>>>>
>>>
>>>
>>
>>
>
>
>
>
Re: try-catch [message #173744 is a reply to message #173562] Wed, 18 August 2004 03:08 Go to previous message
Eclipse UserFriend
72149

"Daniel Megert" <daniel.megert@gmx.net> wrote in message
news:cfsnbn$69k$2@eclipse.org...
> Zohar wrote:
>
> >very unintuitive.
> >can this be fixed?
> >
> >
> Is there a bug report? No bug report - no fix.
>
> Dani
>
> >"Horv
Previous Topic:[ANN] AdvanQas, advanced quick asissts, version 1.2
Next Topic:Refactoring preferences - where are they?
Goto Forum:
  


Current Time: Tue Jul 15 01:18:04 EDT 2025

Powered by FUDForum. Page generated in 0.26760 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top