I wrote this Solidity function:
function getAssetSymbol(IERC20Metadata asset) internal view returns (string memory) {
try asset.symbol() returns (string memory symbol) {
return symbol;
} catch {
return "ERC20";
}
}
And, while testing it, I realized that reverts are not caught when:
asset
is an address that doesn't contain codeasset
returns abytes32
instead ofstring
(e.g. the MKR token does this)
Why is that? I was expecting try/ catch to handle these reverts.