Upgrade to Pro — share decks privately, control downloads, hide ads and more …

例外は"投げない"〜Scalableエラー処理入門

YuitoSato
December 22, 2017

 例外は"投げない"〜Scalableエラー処理入門

https://d-cube.connpass.com/event/74106/
「教養としてのScala ~ そろそろ始めてみたい2017冬」のLTのひとつです。

YuitoSato

December 22, 2017
Tweet

More Decks by YuitoSato

Other Decks in Technology

Transcript

  1. ETDBMB ࣮ࡍʹॻ͍ͯΈΑ͏ def signUp(email: String): Either[Error, User] = { If

    (email.length < 5) { Left(Error(“Too Short Email!”)) } else { Right(User(email)) } } case class Error(msg: String) case class User(email: String) ฦΓ஋ ϝιου new &
 return Class
  2. ETDBMB ࣮ࡍʹॻ͍ͯΈΑ͏ def signUp(email: String): Either[Error, User] = { If

    (email.length < 5) { Left(Error(“Too Short Email!”)) } else { Right(User(email)) } } case class Error(msg: String) case class User(email: String) &JUIFS -FGU
 &SSPS 3JHIU 6TFS
  3. ETDBMB Τϥʔॲཧ΋ڧ੍Ͱ͖Δ def main(args: Array[String]): Unit = { val either=

    signUp(“[email protected]”) either match { case Right(user) => logger.info(user.email) case Left(error) => logger.error(error.msg) } } ੒ޭͳΒ ࣦഊͳΒ