Skip to content

try catch 把我搞抑郁了 #434

Closed Answered by wiasliaw
leiganglee asked this question in Q&A
Discussion options

You must be logged in to vote
  1. try-catch可以捕获什么异常?

只要能發出異常就能被捕捉,revert, require assert 都可以發出異常
catch 後面在乎的是 revert 回來的訊息能不能正確的被解碼

  1. 以下异常返回值类型为bytes的是

revert, require assert 都是回傳 bytes,catch 後面在乎的是回傳的訊息能不能正確的被解碼

  1. try-catch捕获到异常后是否会使try-catch所在的方法调用失败

有可能,catch 解碼失敗的異常沒有辦法被捕捉

  1. try代码块内的revert是否会被catch本身捕获

不會

自己寫的有關 error 的文章:https://wiasliaw.github.io/persona/articles/how-try-catch-works-in-solidity

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
1 reply
@ranxi2001
Comment options

Comment options

You must be logged in to vote
7 replies
@AmazingAng
Comment options

@chenso121
Comment options

@chenso121
Comment options

@KrasCN
Comment options

@shaojunda
Comment options

Comment options

You must be logged in to vote
1 reply
@trylovetom
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by XdpCs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
9 participants