pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C++ paste-bin - collaborative debugging tool View Help


Posted by DD on Wed 20th Jun 12:14 (modification of post by DD view diff)
diff | download | new post

  1. #include <string>
  2. #include <exception>
  3. #include <sstream>
  4.  
  5. class parse_error : public std::exception
  6. {
  7. public:
  8.         parse_error(const std::string& file, size_t line, const std::string& message)
  9.         {
  10.                 _message = (std::ostringstream()
  11.                         << "Error in file "
  12.                         << file
  13.                         << ", line "
  14.                         << line
  15.                         << ":\n"
  16.                         << message
  17.                         ).str();
  18.         }
  19.  
  20.         virtual ~parse_error() { }
  21.  
  22.         virtual const char * what() const throw() { return _message.c_str(); }
  23.  
  24. private:
  25.         std::string _message;
  26. };
  27.  
  28. thrower_function()
  29. {
  30.         throw parse_error("some_file.txt", 42, "Meh.");
  31. }
  32.  
  33. catcher_function()
  34. {
  35.         try {
  36.                 do_something();
  37.                 thrower_function();
  38.                 do_some_other_stuff();
  39.         } catch (parse_error &e) {
  40.                 std::cerr << e.what() << std::endl;
  41.         }
  42. }

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@
:
:
Remember my settings