Beginner, information how can you put a program's error handling into a function
Source: Internet
Author: User
This is a created article in which the information may have evolved or changed. As a novice, you want to handle all the error types of a program in the following ways: such as T=sys printing errors, quit the program ... But there is a problem with that. If an error occurs after a for loop, the loop is skipped with "checkerror" once. But it is problematic to write checkerror only in the for body to perform continue .... I don't know if I made myself clear. Because it is novice, just contact Golang. Previously written C # can handle errors with a try or a delegate. So, I want to ask you a question. Is there a way to put all of the error handling into a function, or can my method be implemented, how to achieve it. Thank you all.//will not send code, too bad to see the Func checkerror (Err error,t string) {if err! = Nil {switch t{case "Sys": FMT. fprintf (OS. Stderr, "Fatal Error:%s", err. Error ()) OS. Exit (1) Case "Conn": Continue}} 255 reads
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service