statement_try_catch_constructor.sol 545 B

123456789101112131415161718192021
  1. contract aborting {
  2. constructor() {
  3. revert("bar");
  4. }
  5. function never() public pure {}
  6. }
  7. contract runner {
  8. function test() public {
  9. try new aborting() returns (aborting a) {
  10. // new succeeded; a holds the a reference to the new contract
  11. } catch Error(string x) {
  12. if (x == "bar") {
  13. // "bar" revert or require was executed
  14. }
  15. } catch (bytes raw) {
  16. // if no error string could decoding, we end up here with the raw data
  17. }
  18. }
  19. }