i'm using play now , here is some code in the controller.class i don't understand :
/**
* Render a 200 OK application/json response
* @param jsonString The JSON string
*/
protected static void renderJSON(String jsonString) {
throw new RenderJson(jsonString);
}
is there any important reason make play framework simply throw a new Render object ? it seems wired to use "throw" without an exception.
Play uses Exceptions for flow control - rather than your methods returning something like a Model, they all throw Exceptions. They are unchecked Exceptions (like NullPointerException, etc) meaning that you don't need a throws
clause on your method signature.
A lot of people are scared by the fact that Play throws Exceptions like this, but it's actually very fast. This is for two reasons
RenderJson
you'll see that a method called fillInStackTrace()
(at least I think that's what it's called) has been overridden to not do anything - creating that detailed stack trace you get when something goes wrong takes a lot of time, but normally that's ok because Exceptions aren't normally thrown all the time. With Play using them for flow control, it was necessary to remove the stack trace generation part of the code.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With