zoukankan      html  css  js  c++  java
  • 自定义异常以及触发异常

    # -*- coding: utf-8 -*-
    
    BADREQUEST = 400
    UNAUTHORIZED = 401
    FORBIDDEN = 403
    GONE = 410
    TOOMANYREQUESTS = 412
    
    
    class DnsdbException(Exception):
        def __init__(self, message, errcode=500, detail=None, msg_ch=u''):
            self.message = message
            self.errcode = errcode
            self.detail = detail
            self.msg_ch = msg_ch
            super(DnsdbException, self).__init__()
    
        def __str__(self):
            return self.message
    
        def json(self):
            return dict(code=self.errcode, why=self.message)
    
    
    class Unauthorized(DnsdbException):
        def __init__(self, message='Unauthorized', errcode=UNAUTHORIZED, detail=None, msg_ch=u''):
            super(Unauthorized, self).__init__(message, errcode, detail, msg_ch)
    
    class Forbidden(DnsdbException):
        def __init__(self, message='Forbidden', errcode=FORBIDDEN, detail=None, msg_ch=u''):
            super(Forbidden, self).__init__(message, errcode, detail, msg_ch)
    
    
    class OperationLogErr(DnsdbException):
        def __init__(self, message, errcode=500, detail=None, msg_ch=u''):
            super(OperationLogErr, self).__init__(message, errcode, detail, msg_ch)
    
    
    class BadParam(DnsdbException):
        def __init__(self, message='Bad params', errcode=BADREQUEST, detail=None, msg_ch=u''):
            super(BadParam, self).__init__(message, errcode, detail, msg_ch)
    
    
    class UpdaterErr(DnsdbException):
        pass
    
    
    class ConfigErr(UpdaterErr):
        def __init__(self, message):
            super(ConfigErr, self).__init__(message=message, errcode=501)

    二、触发异常

    if pidfile is None:
            raise UpdaterErr("No pidfile option found in config file.")
  • 相关阅读:
    URLs
    上班确实累!!!
    转: java 双向map
    HttpReader
    QQ龙虎榜数据接口
    简易行情界面
    下载新浪的行情数据
    淘宝上的大智慧L2数据,月卡最便宜是8元钱,这个也可以获取BBD、DDX等数据!
    获取历史K线数据的几个方法
    好久不写博了.
  • 原文地址:https://www.cnblogs.com/wt11/p/13976647.html
Copyright © 2011-2022 走看看