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
Post a Comment