I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
catch(AnotherException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
// lots of other Exceptions
}
Basically, I want to catch a large set of Exceptions, (maybe always processing the same behaviour). I read the question Catching multiple types of exceptions when writing JSON Catching multiple types of exceptions when writing JSON but I don't use Java 7 (with which I could have all Exceptions in one catch statement) and I do not really want to catch ALL Exceptions, since I want my code to fail in a case I did not expect.
Is there any alternative that would involve fewer branches?
NOTE: What I want to achieve here is not to recover from any Exception, but to categorize the Exceptions. An upper layer is in charge of handling Exceptions, but for this purpose, Exceptions need to be properly categorized.
I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
catch(AnotherException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
// lots of other Exceptions
}
Basically, I want to catch a large set of Exceptions, (maybe always processing the same behaviour). I read the question Catching multiple types of exceptions when writing JSON but I don't use Java 7 (with which I could have all Exceptions in one catch statement) and I do not really want to catch ALL Exceptions, since I want my code to fail in a case I did not expect.
Is there any alternative that would involve fewer branches?
NOTE: What I want to achieve here is not to recover from any Exception, but to categorize the Exceptions. An upper layer is in charge of handling Exceptions, but for this purpose, Exceptions need to be properly categorized.
I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
catch(AnotherException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
// lots of other Exceptions
}
Basically, I want to catch a large set of Exceptions, (maybe always processing the same behaviour). I read the question Catching multiple types of exceptions when writing JSON but I don't use Java 7 (with which I could have all Exceptions in one catch statement) and I do not really want to catch ALL Exceptions, since I want my code to fail in a case I did not expect.
Is there any alternative that would involve fewer branches?
NOTE: What I want to achieve here is not to recover from any Exception, but to categorize the Exceptions. An upper layer is in charge of handling Exceptions, but for this purpose, Exceptions need to be properly categorized.
I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
catch(AnotherException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
// lots of other Exceptions
}
Basically, I want to catch a large set of Exceptions, (maybe always processing the same behaviour). I read the question Catching multiple types of exceptions when writing JSON but I don't use Java 7 (with which I could have all Exceptions in one catch statement) and I do not really want to catch ALL Exceptions, since I want my code to fail in a case I did not expect.
Is there any alternative that would involve fewer branches?
NOTE: What I want to achieve here is not to recover from any Exception, but to categorize the Exceptions. An upper layer is in charge of handling Exceptions, but for this purpose, Exceptions need to be properly categorized.
I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
catch(AnotherException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
// lots of other Exceptions
}
Basically, I want to catch a large set of Exceptions, (maybe always processing the same behaviour). I read the question Catching multiple types of exceptions when writing JSON but I don't use Java 7 (with which I could have all Exceptions in one catch statement) and I do not really want to catch ALL Exceptions, since I want my code to fail in a case I did not expect.
Is there any alternative that would involve fewer branches?
I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
catch(AnotherException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
// lots of other Exceptions
}
Basically, I want to catch a large set of Exceptions, (maybe always processing the same behaviour). I read the question Catching multiple types of exceptions when writing JSON but I don't use Java 7 (with which I could have all Exceptions in one catch statement) and I do not really want to catch ALL Exceptions, since I want my code to fail in a case I did not expect.
Is there any alternative that would involve fewer branches?
NOTE: What I want to achieve here is not to recover from any Exception, but to categorize the Exceptions. An upper layer is in charge of handling Exceptions, but for this purpose, Exceptions need to be properly categorized.
Reducing cyclomatic complexity
I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
catch(AnotherException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e);
}
// lots of other Exceptions
}
Basically, I want to catch a large set of Exceptions, (maybe always processing the same behaviour). I read the question Catching multiple types of exceptions when writing JSON but I don't use Java 7 (with which I could have all Exceptions in one catch statement) and I do not really want to catch ALL Exceptions, since I want my code to fail in a case I did not expect.
Is there any alternative that would involve fewer branches?