Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My rule of thumb is generally to catch exceptions at the top level and log (or otherwise report) them there, because this is where you have the most information about the the error - most importantly the full stack trace.</p> <p>There may be some reasons to catch exceptions in other tiers, however:</p> <ol> <li><em>The exception is actually handled.</em> Eg. a connection failed, but the tier re-tries it.</li> <li><em>The exception is re-thrown with more information</em> (that isn't already available from looking at the stack). Eg. the DAL might report which DB it was trying to connect to, which <code>SqlException</code> wouldn't tell you.</li> <li><em>The exception is translated into a more general exception</em> that is part of the interface for that tier and may (or may not) be handled higher up. Eg. the DAL may catch connection errors and throw a <code>DatabaseUnavailableException</code>. The BL may ignore this for operations that are not critical or it may let it propogate for those that are. If the BL caught <code>SqlException</code> instead it would be exposed to the implementation details of the DAL. Instead the possibility of throwing <code>DatabaseUnavailableException</code> is part of the interface of the DAL.</li> </ol> <p>Logging the same error at multiple tiers is generally not useful, but I can think of one exception: when a lower tier doesn't know whether a problem is critical or not it can log it as a warning. If a higher tier decides that it <em>is</em> critical it can then log the same problem as an error.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload