Consider a nested structure in which the relevant attributes are as follows:
case class Validation { sql: Option[SqlDataSource] }
case class SqlDataSource { dfh: Option[DataFrameHolder] }
case class DataFrameHolder { sql: Option[String] }
The naive way that I am working with this presently is:
val ssql = expVal.sql.getOrElse(
vc.dfh.map(_.sql
.getOrElse(throw new IllegalStateException(s"$logMsg CompareDF: Missing sql container"))
).getOrElse(throw new IllegalStateException(s"$logMsg CompareDF: dfh missing sql"))
.sql.getOrElse(throw new IllegalStateException(s"$logMsg CompareDF: Missing sql")))
While this does get the job done it is also reader-unfriendly and developer unfriendly (tough to get the nesting correctly). Any thoughts on better ways to handle this?
Update thanks for the great answers - this will help clean up and simplify the exception handling code moving forward.