Module 10 ¡ Error Handling: throw, try, catch, finally, and Reading a Stack Trace
When to Throw and When to Return: Exceptions, null, Result Objects, and What to Let Crash
Free with an accountReading
Tanvir and Lima argue about one function. It turns a time like "07:45" into minutes since midnight. Tanvir wants it to throw on bad text, "so nobody can ignore it". Lima wants it to return null, "because throwing for a typo is dramatic". Both have seen code where the other choice went wrong.
Checking what this lesson needs for youâĻ
What is inside When to Throw and When to Return: Exceptions, null, Result Objects, and What to Let Crash
- Three ways to say "it did not work"
- Return null when absence is a normal answer
- Return a result object when the caller must decide every time
- Throw when the caller cannot sensibly go on
- The honest rule
- The top level: log, count, and move on
- What to let crash