wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to get exact error message from print stacktrace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get exact error message from print stacktrace" Watch "How to get exact error message from print stacktrace" New topic
Author

How to get exact error message from print stacktrace

Raghu Sha
Ranch Hand

Joined: Feb 02, 2013
Posts: 118
Hi,
While throwing EntityUniqueConstraintException , getMessage() throws entire statck trace like "insert into <table name> values(<column names>) schemaname.constraintname constarint violation exception

I need to get schemaname.constraintname constarint violation exception alone.

How to extract the message?



} catch (EntityUniqueConstraintException eue) {
System.out.println(eue.getCause());
LOGGER.error("EntityUniqueConstraintException", eue.getCause());
if(eue.getMessage().equals("unique"))
throw new TestBusinessException(eue.getCause(),t.getOperation(), eue.getClass());
}
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1936
    
  28
Welcome to the Ranch.

While throwing EntityUniqueConstraintException , getMessage() throws entire statck trace like "insert into <table name> values(<column names>) schemaname.constraintname constarint violation exception

That's not a stack trace, it looks like an SQL statement template, presumably it's the statement that caused the exception to be thrown.

I need to get schemaname.constraintname constarint violation exception alone.

Not 100% sure what you mean by this.
If want to get an earlier exception that ultimately caused the EntityUniqueConstraintException to be thrown you can work your way down the cause stack by repeatedly calling getCause() on the exception returned from previous call to getCause() until you find an exception of the type you are looking for and then call getMessage() on it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get exact error message from print stacktrace
 
Similar Threads
Updating composite primary column
"auth-constraint" tag
how to recognize integrity constraint from exception
JWCD exam
how many users tomcat support concurrently