Created
April 23, 2015 15:55
-
-
Save rmorrise/df09bdf7d06344bffa1d to your computer and use it in GitHub Desktop.
Grails wrapped exception handling test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wrapped.exception | |
class ExceptionCausingController { | |
def wrappingService | |
def index() { | |
wrappingService.serviceMethod() | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wrapped.exception | |
/** | |
* @author: rmorrise | |
*/ | |
class NestedException extends RuntimeException { | |
NestedException(def message) { | |
super(message) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wrapped.exception | |
import grails.transaction.Transactional | |
@Transactional | |
class NestedService { | |
def serviceMethod() { | |
throw new NestedException("Nested error") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wrapped.exception | |
/** | |
* @author: rmorrise | |
*/ | |
class WrappingException extends RuntimeException { | |
WrappingException(String message, Throwable cause) { | |
super(message, cause) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wrapped.exception | |
import grails.transaction.Transactional | |
@Transactional | |
class WrappingService { | |
def nestedService | |
def serviceMethod() { | |
try { | |
nestedService.serviceMethod() | |
} | |
catch (NestedException e) { | |
throw new WrappingException("Error called nested service from wrapped service: ${e.message}", e) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment