Hacker News new | past | comments | ask | show | jobs | submit login

That's literally the case that "panic" is there to handle.



The example was a worst case example. There are weaker versions thereof, for example the familiar:

    def handle(request):
      try:
          return Response(200, process(request))
      except UserError as ex:
          return Response(400, ex.message)
      except InternalError as ex:
          return Response(500)
The principle stays the same, there is not much to "handle" and no option to recover without external help, either by providing a well-formed request for 400 errors or by providing well-behaving code for 500 errors.


If an error is unrecoverable, panic. If all you're trying to do is generate a 500 error, net/http even handles the panic for you. If you're a library author and unsure of whether your callers want a panic or not, provide a normal and an (idiomatic) "Must" version that panics on the error.

There are legitimate criticisms to be made of how Go's error handling works, but I think the language already handles the case you're talking about.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: