3 ms·
One use case where this is a bit of an problem for me is with a user facing api. Say a web request calls a top level method/subroutine which calls more and so o
by noisy_boy 10y ago
One use case where this is a bit of an problem for me is with a user facing api. Say a web request calls a top level method/subroutine which calls more and so on. Now if there is an error in the the lower level subroutine and I wish to expose it to the user gracefully (say a json response), in Go, I need to handle it explicitly and pass it as part of my return statement (along with the actual results which may be empty/null due to the error). Doing this with each of the nested methods becomes tedious. Please correct me if I'm wrong about this understanding as my knowledge of Go is limited.
If I could raise an exception, taking example of Python, I can choose not to worry about handling it in the intermediate methods and it'll float right to the top level subroutine with error message etc and I can handle it there anyway I wish.