Try to Catch This: Try-Catch in Solidity Reviewed
DeFi Security Summit at Devconnect Argentina 2025 · November 2025 · 3:50
Marc Egli, blockchain security engineer at ChainSecurity, explains why Solidity's try/catch works differently from traditional languages: it applies only to external calls and contract creation, and its behavior depends on how the EVM encodes error data. He covers the three catch types, Error(string), Panic(uint) and raw bytes, plus edge cases such as out-of-gas failures, malformed revert data and nesting.
Speakers
Topics
From DeFi Security Summit at Devconnect Argentina 2025, hosted by DeFi Security Summit.
Transcript
Great. >> Hello everyone. I So I'm Mark. I'm a blockchain security engineer at chain security and I'm going to give this lightning talk to talk about uh try catch in solidity and speak about some edge cases that we um still see are not understood fully by developers and I mean also by some of some auditors sometimes. So here's a recap of some edge cases. So I hope everyone knows what try catch is. Try catch um can can be used uh to wrap external calls or contract creation. And uh there's three different catch clauses that can be used with it. The error, the panic and the
like let's call it the low-level uh clutch uh catch clause. Um so the the error clause would be used um on normal reverts with with a reason and condition whereas like panics would happen when like it is for errors that are not supposed to be there in bug free code such as like arithmetic overflow invalid array accesses or division by zero and asserts. And uh the low-level fallback is uh anything any errors that do not match the above two. So uh for example uh decoding the error data of the error
or the panic if this fails would then be caught in the low-level uh fallback uh clause also out of gas and custom errors would uh fall back into that one. Um and let's do a a small quiz, right? Like this is a simple example external call uh into um interface interface I of a function fu with an argument that comes from an internal call and the question is like can this revert right because we use a low-level catch clause this should catch everything right and turns out there's several reasons right first one if the internal call reverts even though
we are inside our our try we will revert. The second one is a bit more uh complicated is if C is an EOA then solidity performs before we enter the like a try try part we perform an X code size check and if this one fails we will revert. Um since uh 8.10 10. The Xcode size check is is however not done if we expect some non nonzero return data size which is our third reason right if we don't get the expectant return data size from our external on the call we will
also revert and not catch this. So uh generally we can think about it that everything uh all the reverts in the external call will uh in the the co will be caught whereas like reverts coming from the caller and and checks introduced by solid t that are done before the external call will not be caught. Uh yeah so takeaway also reverts inside a try try or catch blocks are not caught as you can see in the above example. Um as I said Xcode size checks and return data size checks are not cut and also
the AI dec code failure on return data uh are caught. Thank you very much. That was all. I hope you have a great day. [applause]