Exception handling
lastmod 2021-11-16created 2021-11-161 edits
Exception handling, or error handling, is a programming language concept or computer hardware architecture designed to handle certain conditions that change the normal flow of execution.
In general, exception handling means stopping processing and doing something else when a particular problem occurs while a program is running.
custom exception vs standard exception
Use standard exceptions actively:
- The exception message alone can convey enough meaning.
- Using standard exceptions improves readability
If you create an exception class for every case, you can end up with too many custom exceptions.
Custom exceptions are needed:
- The name itself can convey information.
- They can provide detailed exception information.
- They improve cohesion of exceptions.
- They make post-exception handling easier.
- They reduce the cost of creating exceptions. (memory issues related to stack traces)