本文整理汇总了Python中PyTango.Except.throw_exception方法的典型用法代码示例。如果您正苦于以下问题:Python Except.throw_exception方法的具体用法?Python Except.throw_exception怎么用?Python Except.throw_exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyTango.Except
的用法示例。
在下文中一共展示了Except.throw_exception方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __exit__
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def __exit__(self,etype,e,tb): #Type of exception, exception instance, traceback
if not e and not etype:
pass
else:
stack = traceback.format_tb(tb)
exstring = '\n'.join(stack)
if self.verbose:
print '-'*80
self.logger.warning('%s Exception Catched, Tracebacks (most recent call last): %s;\n%s'%(etype.__name__,str(e),exstring))
sys.stdout.flush(); sys.stderr.flush()
print '-'*80
if self.postmethod: self.postmethod(exstring)
if etype is DevFailed:
#for k,v in e[0].items():print k,':',v
if True: #not self.rethrow: #re_throw doesn't work!
#The exception is throw just as it was
err = e[0]
Except.throw_exception(err.reason,err.desc,err.origin)
#Except.throw_exception(e.args[0]['reason'],e.args[0]['desc'],e.args[0]['origin'])
else: #It doesn't work!!!
#ex=DevFailed(e[0]['reason'],e[0]['desc'],e[0]['origin'])
#Except.re_throw_exception(ex, '','','')
pass
else: #elif etype is Exception:
exstring = self.origin or len(exstring)<125 and exstring or stack[-1]
Except.throw_exception(etype.__name__,str(e),exstring)
示例2: ReloadMacro
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def ReloadMacro(self, macro_names):
"""ReloadMacro(list<string> macro_names):"""
try:
for macro_name in macro_names:
self.macro_server.reload_macro(macro_name)
except MacroServerException, mse:
Except.throw_exception(mse.type, mse.msg, "ReloadMacro")
示例3: wrapper
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def wrapper(*args,**kwargs):
try:
#logger.debug('Trying %s'%fun.__name__)
result = fun(*args,**kwargs)
#sys.stdout.write('fun DONE!!!\n')
return result
except DevFailed, e:
exstring=getPreviousExceptions()
if verbose:
print '-'*80
#exstring = traceback.format_exc()
logger.warning('DevFailed Exception Catched: \n%s'%exstring)
try:
if showArgs: logger.info('%s(*args=%s, **kwargs=%s)'%(fun.__name__,args,kwargs))
except:pass
sys.stdout.flush(); sys.stderr.flush()
print '-'*80
if postmethod: postmethod(exstring)
err = e.args[0]
if rethrow:
#Except.re_throw_exception(e,'','',"%s(...)"%fun.__name__)
Except.throw_exception(err.reason, exstring, "%s(...)"%fun.__name__)
else:
#Except.throw_exception(err.reason,err.desc,err.origin)
logger.warning(str((err.reason,err.desc,err.origin)))
return default
示例4: read_Data
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def read_Data(self, attr):
desc = "Data attribute is not foreseen for reading. It is used only "\
"as the communication channel for the continuous acquisitions."
Except.throw_exception("UnsupportedFeature",
desc,
"PoolExpChannelDevice.read_Data",
ErrSeverity.WARN)
示例5: ReloadMacroLib
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def ReloadMacroLib(self, lib_names):
"""ReloadMacroLib(sequence<string> lib_names):
"""
try:
for lib_name in lib_names:
self.macro_server.reload_macro_lib(lib_name)
except MacroServerException, mse:
Except.throw_exception(mse.type, mse.msg, "ReloadMacroLib")
示例6: ExceptionWrapper
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def ExceptionWrapper(fun,logger=exLogger,postmethod=None, showArgs=False,verbose=False,rethrow=False,default=None):
'''
Implementation of the popular Catched() decorator:
* it will execute your method within a a try/except
* it will print the traceback
* if :rethrow: is False it will return :default: in case of exception
Example:
@ExceptionWrapper
def funny():
print 'what?'
end
funny()
'''
def wrapper(*args,**kwargs):
try:
#logger.debug('Trying %s'%fun.__name__)
result = fun(*args,**kwargs)
#sys.stdout.write('fun DONE!!!\n')
return result
except DevFailed, e:
exstring=getPreviousExceptions()
if verbose:
print '-'*80
#exstring = traceback.format_exc()
logger.warning('DevFailed Exception Catched: \n%s'%exstring)
try:
if showArgs: logger.info('%s(*args=%s, **kwargs=%s)'%(fun.__name__,args,kwargs))
except:pass
sys.stdout.flush(); sys.stderr.flush()
print '-'*80
if postmethod: postmethod(exstring)
err = e.args[0]
if rethrow:
#Except.re_throw_exception(e,'','',"%s(...)"%fun.__name__)
Except.throw_exception(err.reason, exstring, "%s(...)"%fun.__name__)
else:
#Except.throw_exception(err.reason,err.desc,err.origin)
logger.warning(str((err.reason,err.desc,err.origin)))
return default
except Exception,e:
#exstring = traceback.format_exc()
exstring=getPreviousExceptions()
if verbose:
print '-'*80
logger.error('Python Exception catched: \n%s'%exstring)
try:
if showArgs: logger.info('%s(*args=%s, **kwargs=%s)'%(fun.__name__,args,kwargs))
except:pass
print '-'*80
if postmethod: postmethod(exstring)
if rethrow:
Except.throw_exception('Exception',exstring,"%s(...)"%fun.__name__)
else:
return default
示例7: writeHook
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def writeHook(self, value):
self.__reviewMonitorDependencies()
formula = self._write
modified = self._replaceAttrs4Values(formula, self._writeAttrs)
solution = self._solve(value, modified)
self.debug("write with VALUE=%s, %r means %s" % (value, formula, solution))
if self.write_not_allowed is not None:
if value != solution:
PyTangoExcept.throw_exception("Write %s not allowed" % value,
self.write_not_allowed,
self.owner.name,
ErrSeverity.WARN)
self._lastWrite = solution
return solution
示例8: throw_sardana_exception
# 需要导入模块: from PyTango import Except [as 别名]
# 或者: from PyTango.Except import throw_exception [as 别名]
def throw_sardana_exception(exc):
"""Throws an exception as a tango exception"""
if isinstance(exc, SardanaException):
if exc.exc_info and not None in exc.exc_info:
Except.throw_python_exception(*exc.exc_info)
else:
tb = "<Unknown>"
if exc.traceback is not None:
tb = str(exc.traceback)
Except.throw_exception(exc.type, exc.msg, tb)
elif hasattr(exc, 'exc_info'):
Except.throw_python_exception(*exc.exc_info)
else:
raise exc