4

the following code is giving error, and i dont know whats the reason, and how remove this error, tell me what i am doing wrong.

def members(id:String,name:String) = Action { implicit request =>
    try{
        session.get("userId").map{user=>
            val Data =NewModel.getInfo(id)
            val userId=session.get("userId").get
            if(userId==Data.createdBy){
                Ok(html.groupMembers(Data,"mainAdmin"))
            }else{try{
                    val admin=NewModel.admin(id,userId);
                        Ok(html.members(Data,"subAdmin"))
                 }catch{
                        try{
                            val member=NewModel.member(id,userId)
                                Ok(html.members(Data,"member"));
                        }catch{
                          if(Data.privacy!="secret")
                            Ok(html.members(Data,"outsider"))
                          else
                            Ok(html.noPageFound())
                        }
                 }   
            }   
        }.getOrElse{
            Redirect("/")
        }
    }catch{
        case e=>
          println(e)
          Ok(html.onError())
    }
    }//end groupSetting
  • 3
    That's the compiler telling you that you're using the wrong syntax in your `catch` blocks. But please, for everyone's sake, don't use exceptions for flow control at all. – millhouse Nov 13 '13 at 10:03
  • @millhouse val admin=NewModel.admin(id,userId); giving exception when its not found the value. i am using cassandra at backend –  Nov 13 '13 at 10:05
  • @flavian this is scala code (of controller). i want to send subAdmin a string when he is a admin, cassandra gives null pointer exception if it doesnt found the colum value. so i uses try catch. –  Nov 13 '13 at 13:12
  • This question appears to be off-topic because it is so simple –  Nov 13 '13 at 13:31

1 Answers1

13

use this in every catch block

catch{
    case e=>
      //code
}

Edit:

catch{
    case e:Exception=>
      //code
}
Ravi
  • 182
  • 3
  • 18
Gabber
  • 7,169
  • 3
  • 32
  • 46
  • It's worth noting that a `catch-all` *catch* statement is usually bad practice - http://stackoverflow.com/a/2737554/409976 – Kevin Meredith Jan 11 '14 at 04:39
  • Also, @Amit, I got this `warning` when using your `catch-all` approach - `This catches all Throwables. If this is really intended, use `case e : Throwable` to clear this warning.` – Kevin Meredith Jan 11 '14 at 04:41