I am just learning Go programming language. I just read about the way of error handling in Go. There is a nice explanation but I have some confusion about it. The typical way of handing error in Go is just returning error as a second value of function:
f, err := Sqrt(-1)
if err != nil {
fmt.Println(err)
}
Very simple. But let say I am a library developer and I might want to know the client that my function can throw some error nad client must handle it.
In Java, I have throws
clause. So, client must have to put it in those try...catch
blocks
In Go, I can return error from a function; but let say if client of library avoid to handle it then how do I gracefully tell him to handle it?
Edit: I am just exploring a language. Not trying to mix java's thinking with Go and respect everyone's philosophy of doing it. I just asked because I wanted to know if there is any keyword because I haven't learnt Go very well yet.