title: Is there a way to build exceptions hierarchy in swift?
body: <p>I want to build hierarchy of errors in swift to be able to catch some of my errors specifically, and rest of them as base error, is there any way to do it?</p>
  <p>For example in c++ I can do something like this:</p>
  <pre><code>class BaseException: public std::exception {}
  class Exception1 : public BaseException {}
  class Exception2 : public BaseException {}
  
  void someMethod {
     try {
        doSomethingThrowing()
     }
     catch( const Exception1&amp; ex ) {}
     catch( const BaseException&amp; ex ) { /*I'll get there even if Exception2 was thrown*/}
  }
  </code></pre>
  <p>In swift as I understand, I must throw something implementing Error protocol, but all examples I've found so far implement that protocol as enum and documentation isn't great.
  Is it possible to do something like this</p>
  <pre><code>struct BaseException: Error {}
  struct Exception1: BaseException {}
  struct Exception2: BaseException {}
  
  func someThrowingFunction() throws {}
  
  do {
     try someThrowingFunction()
  } 
  catch Exception1 {} 
  catch BaseException {}
  </code></pre>
  <p>Or should there be some value in catch pattern, and so I must catch same exemplar of Exception1 that was thrown to catch it and I won't be able to catch Exception2 as BaseException at all?</p>