topical media & game development

talk show tell print

professional-program-25-Exceptions-Exceptions.c

? / professional-program-25-Exceptions-Exceptions.c


  include <stdexcept>
  include <iostream>
  
  void throwIf(bool inShouldThrow) throw (std::runtime_error) 
  {
    if (inShouldThrow) {
      throw std::runtime_error("Here's my exception");
    }
  }
  
  int main(int argc, char** argv)
  {
    try {
      throwIf(false); // doesn't throw
      throwIf(true);  // throws!
    } catch (const std::runtime_error& exception) {
      std::cerr << "Caught exception: " << exception.what() << std::endl;
    }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.