{"id":7698,"date":"2025-01-24T03:38:49","date_gmt":"2025-01-24T02:38:49","guid":{"rendered":"https:\/\/wsj-crypto.com\/?p=7698"},"modified":"2025-01-24T03:38:49","modified_gmt":"2025-01-24T02:38:49","slug":"unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements","status":"publish","type":"post","link":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/","title":{"rendered":"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements"},"content":{"rendered":"\n<div id=\"\">\n<p class=\"chakra-text css-gi02ar\">The <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/solidity.readthedocs.io\/en\/latest\/control-structures.html#try-catch\">try\/catch syntax unveiled in 0.6.0<!-- --><\/a> is arguably the most significant advancement in error management functionalities in Solidity, since reason strings for <!-- --><span class=\"chakra-text css-ons8vw\">revert<\/span> and <!-- --><span class=\"chakra-text css-ons8vw\">require<\/span> were introduced in v0.4.22. Both <!-- --><span class=\"chakra-text css-ons8vw\">try<\/span> and <!-- --><span class=\"chakra-text css-ons8vw\">catch<\/span> have been designated keywords <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/solidity.readthedocs.io\/en\/v0.5.9\/miscellaneous.html#reserved-keywords\">since v0.5.9<!-- --><\/a> and now we can leverage them to manage failures in <!-- --><span class=\"chakra-text css-ons8vw\">external<\/span> function transactions without reverting the entire transaction (state changes in the invoked function are still reverted, but those in the invoking function are preserved).<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">We are taking a step away from the strict &#8220;all-or-nothing&#8221; paradigm in a transaction lifecycle, which often does not align with the practical behaviour we usually desire.<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"handling-external-call-failures\">Managing external call failures<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The try\/catch statement enables you to respond to unsuccessful <!-- --><em class=\"chakra-text css-0\">external<!-- --><\/em> calls and <!-- --><em class=\"chakra-text css-0\">contract creation<!-- --><\/em> attempts, hence it cannot be utilized for <!-- --><em class=\"chakra-text css-0\">internal<!-- --><\/em> function calls. Keep in mind that to enclose a public function call within the same contract with try\/catch, it can be executed externally by invoking the function with <!-- --><span class=\"chakra-text css-ons8vw\">this.<\/span>.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The illustration below shows how try\/catch is implemented in a factory model where contract creation may encounter failure. The following <!-- --><span class=\"chakra-text css-ons8vw\">CharitySplitter<\/span> contract necessitates a required address attribute <!-- --><span class=\"chakra-text css-ons8vw\">_owner<\/span> in its constructor.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>pragma solidity ^0.6.1<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span>\n<!-- --><span>contract CharitySplitter <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>    address public owner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    constructor <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address _owner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> public <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        require<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>_owner <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">!=<!-- --><\/span><span> address<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span class=\"token\" style=\"color:rgb(247, 140, 108)\">0<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>, <!-- --><\/span><span class=\"token\" style=\"color:rgb(173, 219, 103)\">\"no-owner-provided\"<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>        owner <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span> _owner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">There exists a factory contract \u2014 <!-- --><span class=\"chakra-text css-ons8vw\">CharitySplitterFactory<\/span> which facilitates the creation and oversight of instances of <!-- --><span class=\"chakra-text css-ons8vw\">CharitySplitter<\/span>. Within the factory, we can encapsulate the <!-- --><span class=\"chakra-text css-ons8vw\">new CharitySplitter(charityOwner)<\/span> within a try\/catch as a precaution in case that constructor fails due to an absent <!-- --><span class=\"chakra-text css-ons8vw\">charityOwner<\/span>.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>pragma solidity ^0.6.1<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(130, 170, 255)\">import<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(173, 219, 103)\">\".\/CharitySplitter.sol\"<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>contract CharitySplitterFactory <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>    mapping <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">&gt;<!-- --><\/span><span> CharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> public charitySplitters<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    uint public errorCount<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    event ErrorHandled<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>string reason<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    event ErrorNotHandled<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>bytes reason<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">function<!-- --><\/span><span> createCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> public <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        try new CharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>            returns <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>CharitySplitter newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>        <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>            charitySplitters<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">[<!-- --><\/span><span>msg.sender<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">]<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span> newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>        <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span> catch <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>            errorCount++<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>        <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Please note that within try\/catch, only exceptions that occur inside the external invocation itself are captured. Issues occurring within the expression are not captured; for instance, if the input parameter for the <!-- --><span class=\"chakra-text css-ons8vw\">new CharitySplitter<\/span> is a part of an internal call, any issues it generates will not be captured. An example illustrating this behavior is the altered <!-- --><span class=\"chakra-text css-ons8vw\">createCharitySplitter<\/span> function. In this instance, the <!-- --><span class=\"chakra-text css-ons8vw\">CharitySplitter<\/span> constructor input parameter is sourced dynamically from another function \u2014 <!-- --><span class=\"chakra-text css-ons8vw\">getCharityOwner<\/span>. If that function fails, in this case with <!-- --><span class=\"chakra-text css-ons8vw\">&#8220;revert-required-for-testing&#8221;<\/span>, that will not be captured in the try\/catch block.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span class=\"token\" style=\"color:rgb(127, 219, 202)\">function<!-- --><\/span><span> createCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address _charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> public <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>    try new CharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>getCharityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>_charityOwner, <!-- --><\/span><span class=\"token\" style=\"color:rgb(255, 88, 116)\">false<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">))<!-- --><\/span><span>\n<!-- --><\/span><span>        returns <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>CharitySplitter newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        charitySplitters<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">[<!-- --><\/span><span>msg.sender<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">]<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span> newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span> catch <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>bytes memory reason<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">..<!-- --><\/span><span>.\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(127, 219, 202)\">function<!-- --><\/span><span> getCharityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address _charityOwner, bool _toPass<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>        internal returns <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>    require<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>_toPass, <!-- --><\/span><span class=\"token\" style=\"color:rgb(173, 219, 103)\">\"revert-required-for-testing\"<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(255, 203, 139)\">return<!-- --><\/span><span> _charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"retrieving-the-error-message\">Retrieving the error message<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">We can further enhance the try\/catch mechanism within the <!-- --><span class=\"chakra-text css-ons8vw\">createCharitySplitter<\/span> function to obtain the error message if one was triggered by a failing <!-- --><span class=\"chakra-text css-ons8vw\">revert<\/span> or <!-- --><span class=\"chakra-text css-ons8vw\">require<\/span> and emit it in an event. There are two methods to accomplish this:<!-- --><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"1-using-catch-errorstring-memory-reason\">1. Using <!-- --><span class=\"chakra-text css-ons8vw\">catch Error(string memory reason)<\/span><\/h3>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span class=\"token\" style=\"color:rgb(127, 219, 202)\">function<!-- --><\/span><span> createCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address _charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> public <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>    try new CharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>_charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> returns <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<span>CharitySplitter newCharitySplitter<!-- --><\/span><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        charitySplitters<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">[<!-- --><\/span><span>msg.sender<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">]<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span> newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span>    catch Error<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>string memory reason<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        errorCount++<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>        CharitySplitter newCharitySplitter <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span> new\n<!-- --><\/span><span>            CharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>msg.sender<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>        charitySplitters<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">[<!-- --><\/span><span>msg.sender<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">]<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span> newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>        \/\/ Emitting the error <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">in<!-- --><\/span><span> event\n<!-- --><\/span><span>        emit ErrorHandled<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>reason<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span>    catch\n<!-- --><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        errorCount++<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Which triggers the subsequent event on a failed constructor require error:<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>CharitySplitterFactory.ErrorHandled<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>\n<!-- --><\/span><span>    reason: <!-- --><\/span><span class=\"token\" style=\"color:rgb(173, 219, 103)\">'no-owner-provided'<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>type: string<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"2-using-catch-bytes-memory-reason\">2. Using <!-- --><span class=\"chakra-text css-ons8vw\">catch (bytes memory reason)<\/span><\/h3>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span class=\"token\" style=\"color:rgb(127, 219, 202)\">function<!-- --><\/span><span> createCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>address charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> public <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>    try new CharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>charityOwner<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>        returns <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>CharitySplitter newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        charitySplitters<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">[<!-- --><\/span><span>msg.sender<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">]<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(127, 219, 202)\">=<!-- --><\/span><span> newCharitySplitter<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span>    catch <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>bytes memory reason<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span>\n<!-- --><\/span><span>        errorCount++<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>        emit ErrorNotHandled<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>reason<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">;<!-- --><\/span><span>\n<!-- --><\/span><span>    <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span\/><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This emits the subsequent event during a failed constructor require mistake:<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>CharitySplitterFactory.ErrorNotHandled<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>\n<!-- --><\/span><span>  reason: hex<!-- --><\/span><span class=\"token\" style=\"color:rgb(173, 219, 103)\">'08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000116e6f2d6f776e65722d70726f7669646564000000000000000000000000000000'<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>type: bytes<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The preceding two approaches for obtaining the error string yield a comparable outcome. The distinction is that the latter method does not ABI-decode the error string. The benefit of the latter method is that it also executes if ABI decoding the error string is unsuccessful or if no reason was supplied.<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"future-plans\">Future intentions<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">There are intentions to introduce support for error categories, meaning we will be able to declare errors in a way similar to events, enabling us to catch various types of errors, for instance:<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-bash\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>catch CustomErrorA<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>uint data1<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span> \u2026 <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span>catch CustomErrorB<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">(<!-- --><\/span><span>uint<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">[<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">]<!-- --><\/span><span> memory data2<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">)<!-- --><\/span><span> <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span> \u2026 <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><span>catch <!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">{<!-- --><\/span><span class=\"token\" style=\"color:rgb(199, 146, 234)\">}<!-- --><\/span><span>\n<!-- --><\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<p><br \/>\n<br \/><a href=\"https:\/\/blog.ethereum.org\/en\/2020\/01\/29\/solidity-0-6-try-catch\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The try\/catch syntax unveiled in 0.6.0 is arguably the most significant advancement in error management functionalities in Solidity, since reason strings for revert and require were introduced in v0.4.22. Both try and catch have been designated keywords since v0.5.9 and now we can leverage them to manage failures in external function transactions without reverting the<\/p>\n","protected":false},"author":3,"featured_media":7699,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[981],"class_list":["post-7698","post","type-post","status-publish","format-standard","has-post-thumbnail","category-ethereum","tag-return-a-list-of-comma-separated-tags-from-this-title-solidity-0-6-x-features-try-catch-statement"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements - WSJ-Crypto<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements - WSJ-Crypto\" \/>\n<meta property=\"og:description\" content=\"The try\/catch syntax unveiled in 0.6.0 is arguably the most significant advancement in error management functionalities in Solidity, since reason strings for revert and require were introduced in v0.4.22. Both try and catch have been designated keywords since v0.5.9 and now we can leverage them to manage failures in external function transactions without reverting the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/\" \/>\n<meta property=\"og:site_name\" content=\"WSJ-Crypto\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-24T02:38:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml\" \/>\n\t<meta property=\"og:image:width\" content=\"1\" \/>\n\t<meta property=\"og:image:height\" content=\"1\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"wsjcrypto\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"wsjcrypto\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/\",\"url\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/\",\"name\":\"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements - WSJ-Crypto\",\"isPartOf\":{\"@id\":\"https:\/\/wsj-crypto.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml\",\"datePublished\":\"2025-01-24T02:38:49+00:00\",\"author\":{\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\"},\"breadcrumb\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#primaryimage\",\"url\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml\",\"contentUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wsj-crypto.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wsj-crypto.com\/#website\",\"url\":\"https:\/\/wsj-crypto.com\/\",\"name\":\"WSJ-Crypto\",\"description\":\"Just Another Crypto News Website\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wsj-crypto.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\",\"name\":\"wsjcrypto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"caption\":\"wsjcrypto\"},\"url\":\"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements - WSJ-Crypto","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/","og_locale":"it_IT","og_type":"article","og_title":"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements - WSJ-Crypto","og_description":"The try\/catch syntax unveiled in 0.6.0 is arguably the most significant advancement in error management functionalities in Solidity, since reason strings for revert and require were introduced in v0.4.22. Both try and catch have been designated keywords since v0.5.9 and now we can leverage them to manage failures in external function transactions without reverting the","og_url":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/","og_site_name":"WSJ-Crypto","article_published_time":"2025-01-24T02:38:49+00:00","og_image":[{"url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml","width":1,"height":1,"type":"image\/jpeg"}],"author":"wsjcrypto","twitter_card":"summary_large_image","twitter_misc":{"Scritto da":"wsjcrypto","Tempo di lettura stimato":"3 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/","url":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/","name":"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements - WSJ-Crypto","isPartOf":{"@id":"https:\/\/wsj-crypto.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#primaryimage"},"image":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#primaryimage"},"thumbnailUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml","datePublished":"2025-01-24T02:38:49+00:00","author":{"@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7"},"breadcrumb":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#primaryimage","url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml","contentUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/01\/solidity-logo.svg.svg+xml"},{"@type":"BreadcrumbList","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/01\/24\/unlocking-error-handling-in-solidity-0-6-x-the-power-of-try-catch-statements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wsj-crypto.com\/"},{"@type":"ListItem","position":2,"name":"Unlocking Error Handling in Solidity 0.6.x: The Power of Try\/Catch Statements"}]},{"@type":"WebSite","@id":"https:\/\/wsj-crypto.com\/#website","url":"https:\/\/wsj-crypto.com\/","name":"WSJ-Crypto","description":"Just Another Crypto News Website","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wsj-crypto.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7","name":"wsjcrypto","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","caption":"wsjcrypto"},"url":"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/7698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/comments?post=7698"}],"version-history":[{"count":2,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/7698\/revisions"}],"predecessor-version":[{"id":7701,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/7698\/revisions\/7701"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media\/7699"}],"wp:attachment":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media?parent=7698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/categories?post=7698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/tags?post=7698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}