Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have long wondered about the syntax of exceptions - if it was:

  void function()
  {
  try:
    function_body...
  catch(Exception e):
  finally:
  }
By leaving the function body in the same indentation as it would be without exception handling, this might help to make the code a little more readable than:

  void function()
  {
    try
    {
      function_body...
    }
    catch(Exception e)
    {
    }
    finally
    {
    }
  }


My mind parsed the first code block as a mix of Python and C. IMO, the later would be more readable since it involves parsing only one rule that the eye is already used.


It reminds me more of C, where labels and goto are often used for error handling (labels using the same `:` syntax).


Now that you you mention labels, I see the similarity to C. I might have been influenced by OP's reference to use indentation to make code more readable instead of using braces.


That would be useful if you only need a try/catch at method level. If you need two try/catch chunks in a method then that wouldn't work.

I do agree that having try/catch at method level would be useful in many ways - as an additional piece of syntax.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: