Bitcoin Forum
November 13, 2024, 03:04:06 PM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: assert и require solidity, отличия  (Read 383 times)
yaroslav195 (OP)
Full Member
***
Offline Offline

Activity: 448
Merit: 109


View Profile
November 03, 2017, 09:12:50 PM
 #1

Чем отличаются assert и require в solidity?
Чет я не очень понял их различия
BlockRe
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
November 04, 2017, 08:24:36 AM
 #2

Чем отличаются assert и require в solidity?
Чет я не очень понял их различия

Hi
Тут самый подробный ответ, который только может быть
https://ethereum.stackexchange.com/questions/15166/difference-between-require-and-assert-and-the-difference-between-revert-and-thro
Jaga-Jaga
Sr. Member
****
Offline Offline

Activity: 613
Merit: 256



View Profile
November 04, 2017, 02:22:32 PM
 #3

Вот что сказано в документации на этот счет, документация в оригинале, надеюсь что вам не составит большого труда понять:
Quote
Error handling: Assert, Require, Revert and Exceptions

Solidity uses state-reverting exceptions to handle errors. Such an exception will undo all changes made to the state in the current call (and all its sub-calls) and also flag an error to the caller. The convenience functions assert and require can be used to check for conditions and throw an exception if the condition is not met. The assert function should only be used to test for internal errors, and to check invariants. The require function should be used to ensure valid conditions, such as inputs, or contract state variables are met, or to validate return values from calls to external contracts. If used properly, analysis tools can evaluate your contract to identify the conditions and function calls which will reach a failing assert. Properly functioning code should never reach a failing assert statement; if this happens there is a bug in your contract which you should fix.

There are two other ways to trigger exceptions: The revert function can be used to flag an error and revert the current call. In the future it might be possible to also include details about the error in a call to revert. The throw keyword can also be used as an alternative to revert().
Вот ссылка на источник: https://solidity.readthedocs.io/en/develop/control-structures.html#error-handling-assert-require-revert-and-exceptions

           ▀██▄ ▄██▀
            ▐█████▌
           ▄███▀███▄
         ▄████▄  ▀███▄
       ▄███▀ ▀██▄  ▀███▄
     ▄███▀  ▄█████▄  ▀███▄
   ▄███▀  ▄███▀ ▀███▄  ▀███▄
  ███▀  ▄████▌   ▐████▄  ▀███
 ███   ██▀  ██▄ ▄██  ▀██   ███
███   ███  ███   ███  ███   ███
███   ███   ███████   ███   ███
 ███   ███▄▄       ▄▄███   ███
  ███▄   ▀▀█████████▀▀   ▄███
   ▀████▄▄           ▄▄████▀
      ▀▀███████████████▀▀
DeepOnion
███
███
███
███
███
███
███
███
███
███
   Anonymity Guaranteed
   Anonymous and Untraceable
   Guard Your Privacy
      ▄▄██████████▄▄
    ▄███▀▀      ▀▀█▀   ▄▄
   ███▀              ▄███
  ███              ▄███▀   ▄▄
 ███▌  ▄▄▄▄      ▄███▀   ▄███
▐███  ██████   ▄███▀   ▄███▀
███▌ ███  ███▄███▀   ▄███▀
███▌ ███   ████▀   ▄███▀
███▌  ███   █▀   ▄███▀  ███
▐███   ███     ▄███▀   ███
 ███▌   ███  ▄███▀     ███
  ███    ██████▀      ███
   ███▄             ▄███
    ▀███▄▄       ▄▄███▀
      ▀▀███████████▀▀
x0r2
Newbie
*
Offline Offline

Activity: 54
Merit: 0


View Profile
November 05, 2017, 09:24:12 AM
 #4

Чем отличаются assert и require в solidity?
Чет я не очень понял их различия
При помощи require проверяются условия для входные данных, при помощи assert ошибки в рантайме.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!