In Sugoi, you can “throw” actions. It could look weird but it's an good choice, because throwing exceptions actually stops the code execution and usually exits the program.
In the context of a web application, you often want to trigger an error message or a redirection and stop the current action.
//Example : Redirect the user to another page if he's not logged function doDashboard(){ if(app.user==null){ throw Redirect("/user/login"); } }
Throwing an Error will display a clean message on the top of the page
//Example : throw an error message if the password does not match function doLogin(){ var u = db.User.manager.select($password == app.params.get("password")); if(u==null){ throw Error("/login","This password does not match with any of our users"); } }
Same concept, with a confirmation message :
function doRecord(product:db.Product,quantity:Int){ var order = Order.recordOrder(product, quantity, app.user); if(order!=null){ throw Ok("/home","You order has been recorded."); }else{ throw Error("/record","Warning, an error occured while processing your order"); } }