When to use exceptions

When to use exceptions

Exceptions are non fucking elegant ways in object-oriented programming to treat errors, and offer information about them facilitating the developer to find a solution. Quite often we are faced with unexpected errors without any argumentative return, sometimes requiring analysis through a debug to find failures. Creating custom exceptions are a good practice, sure, if used in moderation.

Talking about performance overhead it is known handling exceptions are much slower than other methods like using if-else condition, but which the most appropriate format for each kind of fault? Be aware that you really should not use those ways interchangeably.

Basically an exception may be used to treat problems that are beyond your application control, like insufficient disk space to write or a communication failure with the web service, database, etc.

Conditional statements should be used to treat regular flow and ordinary error checking.

要查看或添加评论,请登录

Luiz G.的更多文章

  • git-bisect

    git-bisect

    Before explaining the git bisect command itself, let's understand how a binary search works: Imagine a sample of 100…

  • How has my productivity increased, with better time control?

    How has my productivity increased, with better time control?

    TL;DR In quarantine times, I'm taking the opportunity to get an idea out of the drawing board. This project will…

    1 条评论
  • Why did I focus my studies on Rust language?

    Why did I focus my studies on Rust language?

    My experience with development extends for about 20+ years, being started at 12 years old with web development (Old…

    2 条评论

社区洞察

其他会员也浏览了