Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Go 2: panic on unhandled error #34224

Closed
756445638 opened this issue Sep 11, 2019 · 6 comments

Comments

@756445638
Copy link

commented Sep 11, 2019

golang often use last return as error like this.
f,err = os.OpenFile(...)
if the caller receive the error, and the exception should handle by the caller , nothing changed now .
if the caller not receive the error (include f,_ = os.OpenFile(...)) , the compiler should handle the error , if the error is not nil , the compiler should panic the error.

my idea is this , responsibility is caller's when caller receive the error , otherwise the responsibility is compiler's.

@gopherbot gopherbot added this to the Proposal milestone Sep 11, 2019

@gopherbot gopherbot added the Proposal label Sep 11, 2019

@ianlancetaylor ianlancetaylor changed the title proposal: error handing for golang proposal: Go 2: panic on unhandled error Sep 11, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2019

What if you want to ignore the error?

I expect that this would break a number of existing programs.

@756445638

This comment has been minimized.

Copy link
Author

commented Sep 11, 2019

how about a special token to ignore the error , and the default behvior is panic.
if the error is very import and happend constantly should be handle by caller just like before.
error handing is heavy for programmer , this can reduce a lot work for programmer , and the exception always can be found on a log file .

@756445638

This comment has been minimized.

Copy link
Author

commented Sep 11, 2019

I think this idea can be a litter dangerous for a running server .
If this come true , all program writting in golang require more test.

@756445638

This comment has been minimized.

Copy link
Author

commented Sep 11, 2019

how about automatic logging the unhanled error , print the stack trace .
for the current go programing , a lot of error handing is just logging.
the interface error contains no stack trace , this can be very useful when locate an online problem.

@756445638

This comment has been minimized.

Copy link
Author

commented Sep 11, 2019

so the logging is a default handler for unhandled error , can be very convenvience!!!

@networkimprov

This comment has been minimized.

Copy link

commented Sep 11, 2019

See also #22122

@756445638 756445638 closed this Sep 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.