Reputation: 1721
I have a go code like this,
main()
{
do something
do something
.
.
.
do something
}
Now, I don't know which "do something" is throwing an error. Is it possible in Go to catch the error and print it? How?
Upvotes: 1
Views: 406
Reputation: 3858
Go language did not include exception handling mechanism. However, it has panic/recover mechanism which gives a little bit of exception handling.
Upvotes: 2
Reputation: 118470
You probably want recover
. Alternatively, check the return values from those functions. It's idiomatic in go to call the error value ok
, and immediately check it.
meh, ok := do_something()
if !ok {
Upvotes: 2