final case class CustomException(private val message: String = "",
private val cause: Throwable = None.orNull)
extends Exception(message, cause)
Just try catch:
try {
throw CustomException("optional")
} catch {
case c: CustomException =>
c.printStackTrace
}