Tip 114 Understand the Source of Keywords

Vim is a fast and efficient text editor that will make you a faster and more efficient developer. It's available on almost every OS, and if you master the techniques in this book, you'll never need another text editor. In more than 120 Vim tips, you'll quickly learn the editor's core functionality and tackle your trickiest editi

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Raising an Exception

Programming Elixir ≥ 1.6 — by Dave Thomas (219 / 230)

👈 Appendix 1 Exceptions: raise and try, catch and throw | TOC | catch, exit, and throw 👉

You can raise an exception using the raise function. At its simplest, you pass it a string and it generates an exception of type RuntimeError.

You can also pass the type of the exception, along with other optional fields. All exceptions implement at least the message field.

You can intercept exceptions using the try function. It takes a block of code to execute, and optional rescue, catch, and after clauses.

The rescue and catch clauses look a bit like the body of a case function — they take patterns and code to execute if the pattern matches. The subject of the pattern is the exception that was raised.

Here’s an example of exception handling in action. We define a module that has a public function, start. It calls a different helper function depending on the value of its parameter. With 0, it runs smoothly. With 1, 2, or 3, it causes the VM to raise an error, which we catch and report.

Add a comment

Related posts:

Storing State as Events

MVC and CRUD make software easier to write, but harder to change. Microservice-based architectures can help even the smallest of projects remain agile in the long term, but most tutorials meander in theory or completely miss the point of what it means to be microservice-based. Roll up your sleeves with real projects and learn

Work as a Whole Team to Create the Product

You think agile techniques might be for you, but your projects and organization are unique. An "out-of-the-box" agile approach won't work. Instead, unite agile and lean principles for your project. See how to design a custom approach, reap the benefits of collaboration, and deliver value. For project managers who want to use agi

Meditation and Manifesting

J.P. Morgan once famously said that millionaires don’t need astrologers, but billionaires do. Meditation and manifestation are both practices that involve focusing the mind in order to bring about…