Created
July 2, 2015 12:56
-
-
Save tobia/6c43c1e52f08442cafd8 to your computer and use it in GitHub Desktop.
Simple try & catch taglib for Grails GSP views.
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
// Simple try & catch for GSP views. | |
// | |
// Usage: | |
// | |
// <g:try> | |
// view snippet that needs to be checked | |
// </g:try> | |
// <g:catch> | |
// alternative view code in case of errors; | |
// the exception is available as ${exception} | |
// </g:catch> | |
// | |
class TryCatchTagLib { | |
def Try = { attrs, body -> | |
try { | |
out << body() | |
request.exception = null | |
} catch (Throwable e) { | |
request.exception = e | |
} | |
} | |
def Catch = { attrs, body -> | |
if (request.exception) { | |
out << body(exception: request.exception) | |
request.exception = null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment