title: What is the best exception type to use for an I/O timeout?
body: <p>I've written a Java class that implements a "lock file" to prevent a period job from running more than once concurrently. It's based upon <code>java.nio.channels.FileChannel.tryLock</code> and works quite well.</p>
  
  <p>My class allows client code to supply a timeout value indicating how long it's willing to wait for the lock file to become available, and if a timeout occurs, I'm throwing an <code>IOException</code>. This also works quite well.</p>
  
  <p>But I'm wondering if there is a <em>better</em> exception type to be using, since <code>IOException</code> is fairly generic. Client code catching an <code>IOException</code> wouldn't be able to know if the problem was due to e.g. the timeout itself or some other issue with the filesystem, etc. (unless that other issue throws a subclass of <code>IOException</code> of course).</p>
  
  <p>Briefly leafing through the Java API, I see some candidates but I don't really like any of them for various reasons:</p>
  
  <ol>
  <li><code>java.util.concurrent.TimeoutException</code> (this isn't really a "concurrent" usage)</li>
  <li><code>java.nio.channels.FileLockInterruptionException</code> (docs indicate a very specific reason for this exception; doesn't match my case)</li>
  <li><code>java.nio.channels.InterruptedByTimeoutException</code> (similar reasons to above)</li>
  </ol>
  
  <p>Any suggestions?</p>
  
  <p>I'd prefer something that is available back to Java 7 if possible.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Obviously, a custom exception class is possible, but I was wondering if there was something in the standard API that would be appropriate.</p>