Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Exceptions were designed for exactly that - exceptional circumstances. I try and think of it like this - if you assume everything that you depend on is working as normal for the majority of the time, and method X fails, then it's an exceptional circumstance because it doesn't normally happen and you should define exceptions to catch the situation.</p> <p>So in your situation, you assume the device to be up and running. Therefore exceptional circumstances in this case are the device not accepting a connection, it rejecting a connection, it not accepting data you send it or you not receiving data it should be sending etc. If your devices are routinely turned off several times a day, then you expect them to be turned off, so use return codes or a "bool IsDeviceOn();" method to check it before you connect.</p> <p>If it's something that you <strong>do expect</strong> to happen in normal circumstances, such as querying a device for its capabilities but the one you want isn't available, then use return codes, or a bool method - e.g. "bool DoesDeviceHaveThisCapability();" Don't catch an exception when it doesn't.</p> <p>Another example (for GUI apps) is user input. Don't use exceptions for that, because you do expect a user to input something incorrectly - we're not perfect.</p> <p>I have experienced massive performance issues due to using exceptions when they weren't truly exceptional circumstances. One example was when I was processing a 2GB data file 2-3 times a day. Some lines had valid prices in the format 0.00. Some didn't. I used a FormatException to catch those that didn't.</p> <p>Two years later when I had the chance to get a performance analyser on it, that particular line that caught the exception was responsible for 80% of the time used to analyse the file. I changed that to use the TryParse() method of int instead, and got a massive speed increase.</p> <p>For your examples, I would probably use:</p> <ol> <li>No response from device - exception if devices should be on 24/7, return code if routinely powered off</li> <li>Operation unauthorised - exception</li> <li>Comms failed - exception</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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