Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Exception

 
Samy Ganou
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

I want to have some best practices that concern java exception handling.
I have this situation:

ServiceA use the api apiB

the apiB has methods that throw many type of exception,
methodB1() throws ExceptionB1
methodB2() throws ExceptionB2

On the serviceA I have :
some methods : methodA1() , methodA2() .. these method make calls to methodB1() .. methodBx()
So we have to catch their exceptions.
I have alse a general method
doProcessA() that calls methodA1() .. methodAx()
I want that all methods methodAx() throw one ExceptionA , because i want to do a specific treatement when I have any sort of exception that comes from apiB.

So i write :
methodA(){
try {
methodB();
} catch ( ExceptionB e){
throw new ExceptionA(e.getMessage())
}
}
But i have this problem of best paractices : Preserve Stack Trace : "Caught exception is rethrown, original stack trace may be lost"


Please help
 
Aditya Kanitkar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preserve Stack Trace : "Caught exception is rethrown, original stack trace may be lost"


Is this the error you are getting...??
I'm missing out something...
 
Samy Ganou
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have an error ,
This is a warning when i pass the project on sonar : SONAR is an open source quality management platform..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic