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

Errors are things that can fail after the program is written (hard drive crash, network failure, etc.).

Exceptions are things that were already broken when you wrote the code (null pointer access, index out of bounds, etc.)

To put it another way, exceptions are failures that a sufficiently smart compiler would have been able to catch at compile time. Of course, creating a compiler that smart is a monumental task, so we accept catching some programmer mistakes at runtime as a reasonable tradeoff.



> exceptions are failures that a sufficiently smart compiler would have been able to catch at compile time

Would love to see your proof of this for stack overflow exceptions. You could become very famous.


If you are trying to suggest that the stack is runtime unpredictable like a hard drive, overflowing it would be an error, not an exception.

Therefore, a sufficiently smart compiler just needs to ensure that you have done the proper accounting of stack use and handle the error condition if you are approaching an overflow state. With that, you can prevent it becoming an exception.

If you encounter a stack overflow exception, it is because you didn't do your due diligence. Technically your program is flawed. Granted, the pragmatic engineer probably doesn't care about correctness in that area. It turns out not all programs have to be perfect to be useful.

No fame for me, I'm afraid. There is nothing here out of the ordinary.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: