Get NetBeans exception details as String

View: New views
2 Messages — Rating Filter:   Alert me  

Get NetBeans exception details as String

by iCyclone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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:


>

> 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.





Get NetBeans exception details as String

by bhobiger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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().