@@ -77,6 +77,32 @@ contract FeedConsumer {
7777 errorCount ++ ;
7878 return (0 , false );
7979 } }
80+
81+ function rate4(address token ) public returns (uint value , bool success ) {
82+ // Permanently disable the mechanism if there are
83+ // more than 10 errors.
84+ require (errorCount < 10 );
85+ try feed .getData (token ) returns (uint v ) {
86+ return (v , true );
87+ } catch Error (string memory /* reason*/ ) {
88+ // This is executed in case
89+ // revert was called inside getData
90+ // and a reason string was provided.
91+ errorCount ++ ;
92+ return (0 , false );
93+ } catch Panic (uint /* errorCode*/ ) {
94+ // This is executed in case of a panic,
95+ // i.e. a serious error like division by zero
96+ // or overflow. The error code can be used
97+ // to determine the kind of error.
98+ errorCount ++ ;
99+ return (0 , false );
100+ } catch (bytes memory /* lowLevelData*/ ) {
101+ // This is executed in case revert() was used.
102+ errorCount ++ ;
103+ return (0 , false );
104+ }
105+ }
80106}
81107~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82108pragma solidity ^0.6.0;
@@ -171,6 +197,38 @@ contract FeedConsumer {
171197 return (0 , false );
172198 }
173199 }
200+
201+ function rate4(address token ) public returns (uint256 value , bool success ) {
202+ // Permanently disable the mechanism if there are
203+ // more than 10 errors.
204+ require (errorCount < 10 );
205+ try feed .getData (token ) returns (uint256 v ) {
206+ return (v , true );
207+ } catch Error (
208+ string memory /* reason*/
209+ ) {
210+ // This is executed in case
211+ // revert was called inside getData
212+ // and a reason string was provided.
213+ errorCount ++ ;
214+ return (0 , false );
215+ } catch Panic (
216+ uint256 /* errorCode*/
217+ ) {
218+ // This is executed in case of a panic,
219+ // i.e. a serious error like division by zero
220+ // or overflow. The error code can be used
221+ // to determine the kind of error.
222+ errorCount ++ ;
223+ return (0 , false );
224+ } catch (
225+ bytes memory /* lowLevelData*/
226+ ) {
227+ // This is executed in case revert() was used.
228+ errorCount ++ ;
229+ return (0 , false );
230+ }
231+ }
174232}
175233
176234` ;
0 commit comments