FeaturesPluginsDocs & SupportCommunityPartners

NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Get NetBeans exception details as String

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
iCyclone



Joined: 31 Oct 2009
Posts: 1

PostPosted: Sat Oct 31, 2009 8:38 pm    Post subject: Get NetBeans exception details as String Reply with quote

Hi forum,

while throwing an exception in a try-catch section NetBeans prints some very useful details in a console. I would really like to get those details as a String object.

For example: a servlet throws org.hibernate.exception.ConstraintViolationException while working with PostgreSQL.

In NetBeans console I see the following text:
Quote:

SQL Error: 0, SQLState: null
Batch entry 0 delete from public.account where id=53 was aborted. Call getNextException to see the cause.
SQL Error: 0, SQLState: 23503
ERROR: update or delete on table "account" violates foreign key constraint "fk_work_item_student" on table "work_item"
Details: Key (id)=(53) is still referenced from table "work_item".

Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
(etc)
... 44 more


What I need is to get the bold lines of text as a Stirng object.
I tried to get it in the catch(Exception e) section, but e.toString(), e.getMessage(), e.printStackTrace(out) does not return those lines.

How do I get them?

NetBeans IDE 6.7.1, GlassFish v2.1, PostgreSQL 8.3
Thanks.
Back to top
View user's profile Send private message
bhobiger



Joined: 29 Oct 2009
Posts: 52

PostPosted: Tue Nov 10, 2009 11:45 am    Post subject: Reply with quote

ConstraintViolationException has a method getSQLException(), which should give you the root cause of the exception. Try getMessage() on this. The SQLException itself can have other SQLExceptions nested inside which are accessible via getNextException().
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB