Skip to content

Commit

Permalink
exception handling made more realistic - only swallow in Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Holy committed Apr 13, 2011
1 parent ac85512 commit 30de4fa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Expand Up @@ -46,7 +46,7 @@ public Object interceptAndLog(ProceedingJoinPoint invocation) throws Throwable {
"THE INJECTED CODE SAYS: the method " +
invocation.getSignature().getName() + " failed for the input '" +
invocation.getArgs()[0] + "'. Original exception: " + e);
return null; // normally we would just rethrow it...
throw e;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/iterate/jz2011/codeinjection/aspectj/Main.java
@@ -1,5 +1,6 @@
package iterate.jz2011.codeinjection.aspectj;


/**
* Run the AspectJ example - inject logging of method arguments in the case of an exception to
* a 3rd party class/method.
Expand All @@ -21,6 +22,8 @@ public static void main(String[] args) {

new TooQuiet3rdPartyClass().batchProcess(actualArgs);

} catch (Exception e) {
// ignore - already logged
} finally {
System.out.println("\n############### DONE with the AspectJ example ###############\n");
}
Expand Down
Expand Up @@ -12,12 +12,12 @@ public class TooQuiet3rdPartyClass {
* during a single invocation of a higher-level public method
* and failing for one of the input values.
*/
private void failingMethod(String someArgument) {
private void failingMethod(String someArgument) throws Exception {
if("failNow!".equalsIgnoreCase(someArgument))
throw new RuntimeException("I'm an evil method, I've failed and won't tell for what argument!");
throw new Exception("I'm an evil method, I've failed and won't tell for what argument!");
}

public void batchProcess(String[] batchToProcess) {
public void batchProcess(String[] batchToProcess) throws Exception {
for (String currentArgument : batchToProcess) {
this.failingMethod(currentArgument);
}
Expand Down

0 comments on commit 30de4fa

Please sign in to comment.