自己学写爬虫之----CS240EXCEPTION(一)

#ifndef CS240_EXCEPTION_H
#define CS240_EXCEPTION_H

#include <string>

using namespace std;

class CS240Exception {
 protected:
  std::string message;

 public:
  CS240Exception() : message("Unknown Error") {
    return;
  }
  CS240Exception(const string & msg) : message(msg) {
    return;
  }
  CS240Exception(const CS240Exception & e) : message(e.message) {
    return;
  }
  ~CS240Exception() {
    return;
  }
  const string & GetMessage() {
    return message;
  }
};


class InvalidArgumentException : public CS240Exception {
 public:
  InvalidArgumentException() : CS240Exception("Invalid Argument") {
    return;
  }
  InvalidArgumentException(const string & msg):	CS240Exception(string("Invalid Argument: ") +
															   msg) {
    return;
  }
  InvalidArgumentException(const InvalidArgumentException & e) : CS240Exception(e) {
    return;
  }
  ~InvalidArgumentException() {
    return;
  }
};


class InvalidURLException : public CS240Exception {
 public:
  InvalidURLException() : CS240Exception("Invalid URL") {
    return;
  }
  InvalidURLException(const string & msg) : CS240Exception(string("Invalid URL: ") + msg) {
    return;
  }
  InvalidURLException(const InvalidURLException & e) : CS240Exception(e) {
    return;
  }
  ~InvalidURLException() {
    return;
  }
};


class IllegalStateException : public CS240Exception {
 public:
  IllegalStateException() : CS240Exception("Illegal State") {
    return;
  }
  IllegalStateException(const string & msg) : CS240Exception(string("Illegal State: ") + msg) {
    return;
  }
  IllegalStateException(const IllegalStateException & e) : CS240Exception(e) {
    return;
  }
  ~IllegalStateException() {
    return;
  }
};


class IOException : public CS240Exception {
 public:
  IOException() : CS240Exception("I/O Error") {
    return;
  }
  IOException(const string & msg) : CS240Exception(string("I/O Error: ") + msg) {
    return;
  }
  IOException(const IOException & e) : CS240Exception(e) {
    return;
  }
  ~IOException() {
    return;
  }
};


class NetworkException : public CS240Exception {
 public:
  NetworkException() : CS240Exception("Network Error") {
    return;
  }
  NetworkException(const string & msg) : CS240Exception(string("Network Error: ") + msg) {
    return;
  }
  NetworkException(const NetworkException & e) : CS240Exception(e) {
    return;
  }
  ~NetworkException() {
    return;
  }
};


class FileException : public CS240Exception {
 public:
  FileException() : CS240Exception("File Error") {
    return;
  }
  FileException(const string & msg) : CS240Exception(string("File Error: ") + msg) {
    return;
  }
  FileException(const FileException & e) : CS240Exception(e) {
    return;
  }
  ~FileException() {
    return;
  }
};



#endif
使用:
if(/**/)

else throw InvalidURLException(url);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值