Possible Duplicate:
Throwing exceptions in Scala, what is the “official rule”
How do I handle all exceptions that I can launch from a class? I'm new to Scala and Java I know little, I've never used exceptions.
This is my class:
class Element (var name:String){
}//class Element
Now put a validate method in my class, like this:
class Element (var name:String){
// VALIDAZIONE DI ELEMENT
def validateElement : Boolean = {
val validName : Boolean = try{if(this.name!=null) true
else throw new IllegalArgumentException ("Element: ["+this+"] has no name.")
}catch {
case e: IllegalArgumentException => println("Exception : " + e); false
}
if (validName) true else false
}//def validate
}//class Element
The method works. But I have a single doubt. Where do I put the false of else? Inside the catch clause? As I did?
Thank you very much for your help.