Reputation: 2390
I have a problem,I dont want show full stack-trace when an exception occurs but only the exception type. suppose
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'null' for key 3
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
Here I only want to write the exception type and reason for exception into my log file like
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'null' for key 3
So How to achieve this,I am using java,struts2 and hibernate3. Note: Please no logging frameworks suggestions,Thankyou
Upvotes: 0
Views: 259
Reputation: 5301
Use ex.getMessage()
which returns the detail message string of the exception.
The Throwable
class is the superclass of all errors and exceptions in the Java language. So, You will find more details on Javadoc here.
http://docs.oracle.com/javase/6/docs/api/java/lang/Throwable.html
Upvotes: 1