Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get exact error message from print stacktrace

 
Raghu Sha
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2939
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic