People who are not saints and sages can do nothing, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, Go lang error handling mechanism EP11

Original link: https://v3u.cn/a_id_235

People are not sages and sages, and whoever can have no faults, if they have, they should correct them, and if they do not, they will be encouraged. At the programming language level, there are generally two schools of error handling methods, namely the exception capture mechanism represented by Python (try….catch); and the error return mechanism represented by Golang (returnerror), the former is an automated process, The schematized syntax separates normal logic from error logic, and the latter requires arranging error handling judgments in normal logic. While the schematized syntax is easier to understand, the error-returning mechanism is clearly more advantageous from a system resource overhead perspective. Returning an error Golang’s error (error) is also a data type. Errors are represented by the built-in error type, just like other data types, such as strings, integers, etc. The specific value of the error can be stored in a variable, from the function Returns in: packagemain…

This article is reprinted from: https://v3u.cn/a_id_235
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment