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?
Go language did not include exception handling mechanism. However, it has panic/recover mechanism which gives a little bit of exception handling.
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 {