First, we must understand that errors have different types.
1) Syntax errors: when your code is compiling.
2) Runtime errors: that are caused when executing/running your code.
3) Logic errors: that are caused by you as a programmer during your coding and writing functional logic.
Example of Syntax Error:
This code: will cause a syntax error because it is missing a closing parenthesis, even though the code below it might run if it doesn't depend on it all.
Example of Runtime Error:
Example of Logic Error:
So how can one avoid these errors and what are the best methods for error handling?
These are two of the many ways:
Try & Catch:
try statements are statements that will execute.
If an exception occurs, the exception is placed in e and the catch clause is executed otherwise, the catch clause is skipped. The last clause executes after the try statement is finished,
it executes regardless of whether or not an exception was thrown or caught.
As Programmers, we all knew there many rooms to improve and master our skillsets and coding functionality, there’s no harm in trying, and no shame in admitting failure. There will always be mistakes, it’s what we do about them that matters in the end. I hope that you learned from this blog as much i did reviewing and writing up this content! Happy coding!