Performance considerations
One common myth about exception handling is that it doesn’t affect performance. If exceptions are significantly harming the application’s performance, that’s a sign that exceptions are being used too much. Exceptions should not control the flow of the application whatsoever.
Ideally, the code should flow with no interruptions. In small web applications with a few users, this type of approach may be adequate, but for high-performing, high-traffic websites, placing a try
/catch
block in frequently-called code may cause the site to suffer a performance hit.
In this section, we covered what exception handling was, reviewed the two types of errors in applications, identified where exception handling is ideal, and covered some of the performance myths regarding exceptions. Next, we’ll look at some common exception handling techniques.