python 异常处理

标签 python

在下面的 python 中,不会打印消息 RSU is not support on single node machine**。有人可以帮忙吗??

#! /usr/bin/env python

import sys

class SWMException(Exception):
    def __init__(self, arg):
        print "inside exception"
        Exception.__init__(self, arg)

class RSUNotSupported(SWMException):
    def __init__(self):
        SWMException.__init__(self, "**RSU is not supported on single node machine**")

def isPrepActionNeeded():
    if 1==1:
        raise RSUNotSupported()
try:
    isPrepActionNeeded()
except:
    sys.exit(1)

最佳答案

它没有被打印,因为你甚至没有尝试打印它:)这里:

try:
    isPrepActionNeeded()
except RSUNotSupported as e:
    print str(e)
    sys.exit(1)

关于python 异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7022148/

相关文章:

Python多处理+子进程问题

Python:将值从一个函数传递到另一个函数

python - Beautiful Soup - 下载 css 元素

python - 没有名为 rest_authusers 的模块错误

python : multiprocessing managament

python - 类型错误 : Object of type 'type' is not JSON serializable

python - 如何在Python中捕获特定的ExecuteError?

python - 如何找到 tarball 的一致散列

python - Soundcloud API python 与链接分区相关的问题

python - 将单行文本写成多行的 Pythonic 方法是什么