Book Image

Blockchain for Enterprise

By : Narayan Prusty
Book Image

Blockchain for Enterprise

By: Narayan Prusty

Overview of this book

The increasing growth in blockchain use is enormous, and it is changing the way business is done. Many leading organizations are already exploring the potential of blockchain. With this book, you will learn to build end-to-end enterprise-level decentralized applications and scale them across your organization to meet your company's needs. This book will help you understand what DApps are and how the blockchain ecosystem works, via real-world examples. This extensive end-to-end book covers every blockchain aspect for business and for developers. You will master process flows and incorporate them into your own enterprise. You will learn how to use J.P. Morgan’s Quorum to build blockchain-based applications. You will also learn how to write applications that can help communicate enterprise blockchain solutions. You will learn how to write smart contracts that run without censorship and third-party interference. Once you've grasped what a blockchain is and have learned about Quorum, you will jump into building real-world practical blockchain applications for sectors such as payment and money transfer, healthcare, cloud computing, supply chain management, and much more.
Table of Contents (14 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Exceptions


In some cases, exceptions are thrown automatically. You can use assert(), revert(), and require() to throw manual exceptions. Exceptions stop and revert any currently-executing calls (that is, all changes to the state and balances are undone). In Solidity, it is not yet possible to catch exceptions.

The following three lines are all different ways of throwing exceptions in Solidity:

if(x != y) { revert(); }

//In assert() and require(), the conditional statement is an inversion //to "if" block's condition, switching the comparison operator != to ==
assert(x == y);
require(x == y);

assert() will take away all the gas, whereas require() and revert() will refund the remaining gas. 

Note

Solidity doesn't support returning a reason for exceptions but is expected to soon. You can visit the https://github.com/ethereum/solidity/issues/1686 issue for an update. Then you will be able to write revert("Something bad happened") and require(condition, "Something bad happened").