Guest User

Untitled

a guest
Dec 13th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //Been seeing a lot of this lately in various repos. This is unnecessary because you're simply
  2. //rethrowing the same error that would have been thrown anyway thus rendering your try/catch block useless:
  3. try {
  4. //execute some code..
  5. } catch(error) {
  6. throw error;
  7. }
  8.  
  9. //The only reason to catch an error is to either handle that error or log it:
  10. try {
  11. //execute some code..
  12. } catch(error) {
  13. loggerInstance.error('Some error occurred performing some operation...', error);
  14. throw error;
  15. }
  16.  
  17. //or handle the error by returning a value that can be used by the caller:
  18. try {
  19. //execute some code..
  20. } catch(error) {
  21. return someDefaultValue;
  22. }
Add Comment
Please, Sign In to add comment