Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Template for try/catch block(to speed up debug)
Template for try/catch block [message #758521] Wed, 23 November 2011 14:54 Go to next message
spam.dump.one is currently offline spam.dump.oneFriend
Messages: 2
Registered: November 2011
Junior Member
I've seen that when I'm not handling an exception in Java, Eclipse provides me with a "surround with try/catch block" quick fix.

That fix seems to make use of a template, but I can't find it.

I'd like to configure that template so that the catch block prints on System.err some info:
- name of the exception
- name of the method that invoked it
- name of the class
- name of the thread (eventually)

Is this possible to do this automatically?
Re: Template for try/catch block [message #758526 is a reply to message #758521] Wed, 23 November 2011 15:14 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 11/23/2011 8:24 PM, spam.dump.one wrote:
> That fix seems to make use of a template, but I can't find it.

- Open 'Templates' view.
- Look for a template named 'try'

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Re: Template for try/catch block [message #758528 is a reply to message #758521] Wed, 23 November 2011 15:17 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 23.11.2011 15:54, spam.dump.one wrote:
> I've seen that when I'm not handling an exception in Java, Eclipse
> provides me with a "surround with try/catch block" quick fix.
>
> That fix seems to make use of a template, but I can't find it.
>
> I'd like to configure that template so that the catch block prints on
> System.err some info:
> - name of the exception
> - name of the method that invoked it
> - name of the class
> - name of the thread (eventually)
>
> Is this possible to do this automatically?
Window > Preferences > Java > Code Style > Code Templates: Code > Catch
block body

Dani
Re: Template for try/catch block [message #758539 is a reply to message #758528] Wed, 23 November 2011 15:41 Go to previous messageGo to next message
spam.dump.one is currently offline spam.dump.oneFriend
Messages: 2
Registered: November 2011
Junior Member
Thank you.

Do I have to use reflection to know the name of the kind of exception that's prompted, or is there some {} parameter I can refer to?

For example
System.err.println("Exception" + {exception_type} + "in method" + {method} + "of class" + {class});

[Updated on: Wed, 23 November 2011 15:42]

Report message to a moderator

Re: Template for try/catch block [message #758835 is a reply to message #758539] Thu, 24 November 2011 16:40 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 11/23/2011 9:11 PM, spam.dump.one wrote:
> Thank you.
>
> Do I have to use reflection to know the name of the kind of exception
> that's prompted, or is there some {} parameter I can refer to.

Don't think it is possible to get the exact exception type thrown from
selected code via a template.

The complete list of template variables is here -
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-template-variables.htm

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Re: Template for try/catch block [message #759582 is a reply to message #758539] Tue, 29 November 2011 09:20 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 23.11.2011 16:41, spam.dump.one wrote:
> Thank you.
>
> Do I have to use reflection to know the name of the kind of exception
> that's prompted, or is there some {} parameter I can refer to.
Try:

System.out.println(${exception_var}.getClass().getName());
System.out.println(${exception_var}.getStackTrace()[0].getMethodName());
System.out.println("${enclosing_type}");
System.out.println(Thread.currentThread().getName());

Dani
>
> For example
> System.err.println("Exception" + {exception_type} + "in method" +
> {method} + "of class" + {class});
Previous Topic:Save "run as configuration" settings in project files does NOT work: Really export project
Next Topic:Android dev: NoClassDefFoundError on one machine but not another
Goto Forum:
  


Current Time: Thu Apr 18 08:31:04 GMT 2024

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

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

Back to the top