Catch exception in Scala constructor -


what scala equivalent of java code, somemethodthatmightthrowexception defined elsewhere?

class myclass {     string a;     string b;      myclass() {         try {             this.a = somemethodthatmightthrowexception();             this.b = somemethodthatmightthrowexception();         } {             system.out.println("done");         }     } } 

class myclass {   private val (a, b) =     try {       (somemethodthatmightthrowexception(),        somemethodthatmightthrowexception())     } {       println("done")     } } 

try expression in scala, can use it's value. tuples , pattern matching can use statement more 1 value.

alternatively use same code in java:

class myclass {   private var a: string = _   private var b: string = _    try {     = somemethodthatmightthrowexception()     b = somemethodthatmightthrowexception()   } {     println("done")   } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -