求助:关于CFX浮点错误 Floating point pdoexception 错误:Overflow

2238人阅读
&&&&&&&& 使用异常处理机制
&&&&&&&& 常用异常类
2、Python异常处理机制
2.1、异常处理关键字
检查代码块
捕捉处理异常
一个try可连续使用多个except
一个except可捕捉多种异常
except Exception, e:
& #处理异常
except (ValueError, TypeErroe), e:
& #一个except处理多个异常
try无异常时执行
无论异常与否,必执行
触发抛出异常
raise [SomeException [,args[,traceback]]]
#traceback:异常触发时的跟踪记录对象
2.2、异常处理流程示例
& #检查代码块
except ValueError, e:
& #处理ValueError
except TypeError, e
&&#处理TypeError
except Exception, e
& raise& string, “new exception” &#抛出异常
& #无异常时,执行
& #清理垃圾
3、常用异常类
3.1、异常类继承树
3.2 异常类Exception属性
3.2.1继承自BaseException的
raise Exception [,args [, traceback]] 中的args,元组类型
raise Exception, (“error message”, errorno)
Exception(“my message”), “my message” 为message属性值
注(’my message’,)为args元组
__reduce__
__reduce__(self):序列化自身
__setstate__
当处理unpickling(不可序列化) 的对象的实例属性时,可以使用特殊的方法_getstate_()&和&_setstate_()来修改类实例的状态。
__unicode__
解码为unicode对象
装饰器(slot wrapper)
返回可读字符串
representation,返回可解析的字符串。它的返回值通常可以用来重新获得该对象,通常情况下 obj==eval(repr(obj))
__setattr__
添加(属性/值)对,__setattr__(self, key, value)&&&
__delattr__
删除(属性/值)对,__delattr__ (self, key)
__getattribute__
获取属性,__getattr__ (self, key)
__getitem__
迭代args元组
__getslice__
获取args元组片段,__getslice__(i,j) = __getitem__(slice(i,j)
3.2.2继承自Object
__subclasshook__
__subclasshook__(subclass)
判断subclass是否为本类的子类
__format__
接受一个格式化指示符作为参数,来控制怎样格式化自己。
__format__(self,&format_spec)&&&&&
__reduce_ex__
__reduce_ex__(self, protocol)
当pickling时被调用,如果没有,则调用__reduce__,若也没有,则此类可以正常pickling
__sizeof__
获取对象占用字节数
计算对象的hash键值
3.3异常类列表
BaseException
SystemExit
python解释器请求退出
KeyboardInterrupt
用户中断执行(ctl+c)
常规错误的基类
StopIteration
迭代器没有更多值
GeneratorExit
生成器异常请求退出
ArithmeticError
所有数值计算错误基类
FloatingPointError
浮点计算错误
OverflowError
数值溢出异常
ZeroDivisionError
AssertionError
断言语句异常
AttributeError
对象没有这个属性
到达EOF标记
EnvironmentError
操作系统错误基类
输入输出操作失败
操作系统错误
WindowsError
Windows系统调用失败
ImportError
导入模块/对象失败
KeyboardInterrupt
用户中断执行(ctrl+c)
LookupError
无效数据查询基类
IndexError
序列中没有此索引
映射中没有此键
MemoryError
未声明/未初始化对象
UnboundLocalError
访问未初始化本地变量
ReferenceError
弱引用访问已回收对象错误
RuntimeError
一般运行时错误
NotImplementatedError
尚未实现的方法
SystemError
一般的解释器系统错误
IndentationError
Tab和空格混用
SyntaxError
python语法错误
对类型无效的操作
ValueError
传入无效的参数
UnicodeError
Unicode相关错误
UnicodeDecodeError
Unicode解码错误
UnicodeEncodeError
Unicode编码错误
UnicodeTranslatError
Unicode转换错误
警告的基类
DeprecationWarning
关于被弃用特征的警告
FutureWarning
构造将来语义会有改变的警告
OverflowWarning
自动提升长整型警告&& 2.4弃用
PendingDeprecationWarning
特性将被弃用的警告
RuntimeWarning
可疑的运行时行为的警告
SyntaxWarning
可疑语法的警告
UserWarning
用户代码生成警告
1、__setstate__ : 修改Foo对象的状态(修改打开的文件,和写入位置)
class Foo(object):
&&& def __init__(self, value, filename):
&&&&&&& self.value = value
&&&&&&& self.logfile = file(filename, 'w')
&&& def __getstate__(self):
&&&&&&& &&&Return state values to be pickled.&&&
&&&&&&& f = self.logfile
&&&&&&& return (self.value, f.name, f.tell())
&&& def __setstate__(self, state):
&&&&&&& &&&Restore state from the unpickled state values.&&&
&&&&&&& self.value, name, position = state
&&&&&&& f = file(name, 'w')
&&&&&&& f.seek(position)
&&&&&&& self.logfile = f
2、__setattr__,__delattr__, __getattr__
class storage(dict):
&&&&#通过使用__setattr__, __getattr__, __delattr__
&&&&#可以重写dict,使之通过“.”调用
&&&&def&__setattr__(self, key, value):
&&&&&&&&self[key] = value
&&&&def __getattr__ (self, key):
&&&&&&&&try:
&&&&&&&&&&&&return self[key]
&&&&&&&&except KeyError, k:
&&&&&&&&&&&&return None
&&&&def __delattr__ (self, key):
&&&&&&&&try:
&&&&&&&&&&&&del self[key]
&&&&&&&&except KeyError, k:
&&&&&&&&&&&&return None
3、__format__()
def&__format__(self,&format_spec):
&if&isinstance(format_spec,&unicode):
&&return&unicode(str(self))
&&return&str(self)
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:66027次
积分:1024
积分:1024
排名:千里之外
原创:38篇
转载:11篇
(10)(4)(1)(2)(4)(7)(5)(12)(1)(1)(1)(1)28.16. fpectl — Floating point exception control & Python 2.7.13 documentation
— Floating point exception control
module is not built by default, and its usage is discouraged
and may be dangerous except in the hands of experts.
See also the section
on limitations for more details.
Most computers carry out floating point operations in conformance with the
so-called IEEE-754 standard. On any real computer, some floating point
operations produce results that cannot be expressed as a normal floating point
value. For example, try
&&& import math
&&& math.exp(1000)
&&& math.exp(1000) / math.exp(1000)
(The example above will work on many platforms. DEC Alpha may be one exception.)
“Inf” is a special, non-numeric value in IEEE-754 that stands for “infinity”,
and “nan” means “not a number.” Note that, other than the non-numeric results,
nothing special happened when you asked Python to carry out those calculations.
That is in fact the default behaviour prescribed in the IEEE-754 standard, and
if it works for you, stop reading now.
In some circumstances, it would be better to raise an exception and stop
processing at the point where the faulty operation was attempted. The
module is for use in that situation. It provides control over
floating point units from several hardware manufacturers, allowing the user to
turn on the generation of SIGFPE whenever any of the IEEE-754
exceptions Division by Zero, Overflow, or Invalid Operation occurs. In tandem
with a pair of wrapper macros that are inserted into the C code comprising your
python system, SIGFPE is trapped and converted into the Python
exception.
module defines the following functions and may raise the given
exception:
fpectl.turnon_sigfpe()
Turn on the generation of SIGFPE, and set up an appropriate signal
fpectl.turnoff_sigfpe()
Reset default handling of floating point exceptions.
exception fpectl.FloatingPointError
has been executed, a floating point operation that
raises one of the IEEE-754 exceptions Division by Zero, Overflow, or Invalid
operation will in turn raise this standard Python exception.
28.16.1. Example
The following example demonstrates how to start up and test operation of the
&&& import fpectl
&&& import fpetest
&&& fpectl.turnon_sigfpe()
&&& fpetest.test()
FloatingPointError: Overflow
FloatingPointError: Division by zero
[ more output from test elided ]
&&& import math
&&& math.exp(1000)
Traceback (most recent call last):
File &&stdin&&, line 1, in &module&
FloatingPointError: in math_1时间: 16:01:01
&&&& 阅读:20
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&一、内置异常
异常名称描述
BaseException
所有异常的基类
SystemExit
解释器请求退出
KeyboardInterrupt
用户中断执行(通常是输入^C)
常规错误的基类
StopIteration
迭代器没有更多的值
GeneratorExit
生成器(generator)发生异常来通知退出
StandardError
所有的内建标准异常的基类
ArithmeticError
所有数值计算错误的基类
FloatingPointError
浮点计算错误
OverflowError
数值运算超出最大限制
ZeroDivisionError
除(或取模)零 (所有数据类型)
AssertionError
断言语句失败
AttributeError
对象没有这个属性
没有内建输入,到达EOF 标记
EnvironmentError
操作系统错误的基类
输入/输出操作失败
操作系统错误
WindowsError
系统调用失败
ImportError
导入模块/对象失败
LookupError
无效数据查询的基类
IndexError
序列中没有此索引(index)
映射中没有这个键
MemoryError
内存溢出错误(对于Python 解释器不是致命的)
未声明/初始化对象 (没有属性)
UnboundLocalError
访问未初始化的本地变量
ReferenceError
弱引用(Weak reference)试图访问已经垃圾回收了的对象
RuntimeError
一般的运行时错误
NotImplementedError
尚未实现的方法
SyntaxError
Python 语法错误
IndentationError
Tab 和空格混用
SystemError
一般的解释器系统错误
对类型无效的操作
ValueError
传入无效的参数
UnicodeError
Unicode 相关的错误
UnicodeDecodeError
Unicode 解码时的错误
UnicodeEncodeError
Unicode 编码时错误
UnicodeTranslateError
Unicode 转换时错误
警告的基类
DeprecationWarning
关于被弃用的特征的警告
FutureWarning
关于构造将来语义会有改变的警告
OverflowWarning
旧的关于自动提升为长整型(long)的警告
PendingDeprecationWarning
关于特性将会被废弃的警告
RuntimeWarning
可疑的运行时行为(runtime behavior)的警告
SyntaxWarning
可疑的语法的警告
UserWarning
用户代码生成的警告
二、自定义异常
捕捉异常格式
#运行别的代码
except &异常名&:
#如果在try部份引发了‘name‘异常
except &异常名&,&数据&:
#如果引发了‘name‘异常,获得附加的数据
#如果没有异常发生
&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:/buchizaodian/p/6985323.html
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!君,已阅读到文档的结尾了呢~~
浮点数学函数异常处理方法
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
浮点数学函数异常处理方法
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口}

我要回帖

更多关于 poixmlexception错误 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信