How error propagate between contracts in Solidity?

Julien Klepatch

Let's say we have 2 smart contracts. A and B. A calls B, and B throws an error.

What happen in A?

Not sure? haha, that's a tricky one!

Actually it depends on how B was called.

If B was called the normal way, the whole transaction get reverted:

contract A {
  function foo() {
   B b = new B();
   b.willThrow();
  }
}
contract B {
  function willThrow() {
    revert();
  }
}

BUT, if B was called with a low-level call() method, the error will NOT be propagated to A. Instead, A will received a false boolean value indicating there was an error in B. This way, A can recover from the error and handle the error itself.

Check out this video where I explain this in full details, as well as other error handling mechanisms in Solidity like assert, revert, require and throw.

By the way, in the Dapp 30 course, there is a bonus section dedicated to debugging in Solidity when I explain in details the different kind of errors in Solidity and how to debug them.

0 Comments

Leave a Reply

More great articles

Top 2 Ethereum token standards every Dapp developer should now

If you are a developer building an Ethereum Dapp or an ICO, you probably heard of Ethereum token standards. ERC20,…

Read Story

New course for testing Solidity smart contracts

After you deploy a web application, you can always change its code if you need to add a feature or…

Read Story

How to manipulate strings in Solidity?

Manipulating strings in Solidity is notoriously difficult. This is surprising for most developers who are used to manipulating easily in…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]
Arrow-up