- Scala Programming Projects
- Mikael Valot Nicolas Jorand
- 231字
- 2021-07-23 16:25:24
Handling Errors
In this chapter, we will continue working on the retirement calculator that we implemented in Chapter 2, Developing a Retirement Calculator. Our calculator worked correctly as long as we passed the right arguments, but would fail badly with a horrible stack trace if any of the parameters were wrong. Our program only worked for what we call the happy path.
The reality of writing production software is that all kinds of error scenarios can occur. Some of them are recoverable, some of them must be presented to the user in an attractive way, and, for some hardware-related errors, we might need to let the program crash.
In this chapter, we will introduce exception handling, explain what referential transparency is, and try to convince you that exceptions are not the best way to deal with errors. Then, we will explain how to use functional programming constructs to effectively handle the possibility of an error.
In each section, we will briefly introduce a new concept, and then use it in a Scala worksheet to get a sense of how to use it. After that, we will apply this new knowledge to improve the retirement calculator.
In this chapter, we will look at the following topics:
- Using exceptions when necessary
- Understanding referential transparency
- Using Option to represent optional values
- Using Either to handle errors sequentially
- Using Validated to handle errors in parallel
- 廣電5G從入門到精通
- 智能網聯汽車V2X與智能網聯設施I2X
- Truffle Quick Start Guide
- 物聯網之魂:物聯網協議與物聯網操作系統
- 計算機網絡安全實訓教程(第二版)
- 農產品物聯網研究與應用
- 物聯網時代
- PLC、現場總線及工業網絡實用技術速成
- Building RESTful Web Services with Spring 5(Second Edition)
- Mastering Dart
- 基于性能的保障理論與方法
- Master Apache JMeter:From Load Testing to DevOps
- 從實踐中學習手機抓包與數據分析
- 5G技術核心與增強:從R15到R17
- Hands-On Bitcoin Programming with Python