Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get exact error message from print stacktrace

 
Raghu Sha
Ranch Hand
Posts: 124
  • 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
Saloon Keeper
Posts: 3145
74
  • 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.
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!