当使用C++目标的释放模式时,为什么这个Haxe try-catch块仍然崩溃
Why is this Haxe try-catch block still crashing, when using Release mode for C++ target
我有一个HaxeFlixel项目,它在调试模式下可以正常工作,用于其他目标,包括flash、neko和windows。但是在发布模式中以Windows为目标,我遇到了一个意外的崩溃,令人惊讶的是,它发生在一个try-catch块内。以下是崩溃功能:
/**
* Will safely scan a parent node's children, search for a child by name, and return it's text.
* @param parent an Fast object that is parent of the `nodeNamed` node
* @param nodeName the node's name or a comma-separated path to the child (will scan recursively)
* @return node's text as String, or null if child is not there
*/
public static function getNodeText(parent:Fast, nodeName:String):String {
try {
var _node : Fast = getNodeNamed(parent, nodeName);
//if (_node == null)
// return null;
// next line will crash if _node is null
var it :Iterator<Xml> = _node.x.iterator();
if ( it == null || !it.hasNext() )
return null;
var v = it.next();
var n = it.next();
if( n != null ) {
if( v.nodeType == Xml.PCData && n.nodeType == Xml.CData && StringTools.trim(v.nodeValue) == "" ) {
var n2 = it.next();
if( n2 == null || (n2.nodeType == Xml.PCData && StringTools.trim(n2.nodeValue) == "" && it.next() == null) )
return n.nodeValue;
}
//does not only have data (has children)
return null;
}
if( v.nodeType != Xml.PCData && v.nodeType != Xml.CData )
//does not have data";
return null;
return v.nodeValue;
}catch (err:Dynamic) {
trace("Failed parsing node Text [" + nodeName+"] " + err );
return null;
}
}
通过启用if (_node == null) return null;
线路,它再次安全工作。通过将错误捕获为Dynamic
,我认为我应该捕获所有可能的错误类型!为什么会发生这种情况?为什么它会以发布模式出现?
我的IDE是FlashDevelop,我使用的是HaxeFlixel 3.3.6、lime 0.9.7和openFL 1.4.0,如果这对有什么不同的话
编辑:我怀疑这与翻译的C++代码如何错过Dynamic
异常有关。等效生成的C++代码是:
STATIC_HX_DEFINE_DYNAMIC_FUNC2(BaxXML_obj,_getNodeNamed,return )
::String BaxXML_obj::getNodeText( ::haxe::xml::Fast parent,::String nodeName){
HX_STACK_FRAME("bax.utils.BaxXML","getNodeText",0x4a152f07,"bax.utils.BaxXML.getNodeText","bax/utils/BaxXML.hx",56,0xf6e2d3cc)
HX_STACK_ARG(parent,"parent")
HX_STACK_ARG(nodeName,"nodeName")
HX_STACK_LINE(56)
try
{
HX_STACK_CATCHABLE(Dynamic, 0);
{
HX_STACK_LINE(57)
::haxe::xml::Fast _node = ::bax::utils::BaxXML_obj::getNodeNamed(parent,nodeName); HX_STACK_VAR(_node,"_node");
HX_STACK_LINE(63)
Dynamic it = _node->x->iterator(); HX_STACK_VAR(it,"it");
// ... Let's skip the irrelevant code
}
catch(Dynamic __e){
{
HX_STACK_BEGIN_CATCH
Dynamic err = __e;{
HX_STACK_LINE(82)
::String _g5 = ::Std_obj::string(err); HX_STACK_VAR(_g5,"_g5");
HX_STACK_LINE(82)
::String _g6 = (((HX_CSTRING("Failed parsing node Text [") + nodeName) + HX_CSTRING("] ")) + _g5); HX_STACK_VAR(_g6,"_g6");
HX_STACK_LINE(82)
::haxe::Log_obj::trace(_g6,hx::SourceInfo(HX_CSTRING("BaxXML.hx"),82,HX_CSTRING("bax.utils.BaxXML"),HX_CSTRING("getNodeText")));
HX_STACK_LINE(83)
return null();
}
}
}
HX_STACK_LINE(56)
return null();
}
您定义了哪些haxedef?
将这些添加到project.xml中可能会有所帮助:
<haxedef name="HXCPP_CHECK_POINTER"/> <!--makes null references cause errors-->
<haxedef name="HXCPP_STACK_LINE" /> <!--if you want line numbers-->
<haxedef name="HXCPP_STACK_TRACE"/> <!--if you want stack traces-->
您也可以尝试crashdumper库:https://github.com/larsiusprime/crashdumper
(Crashdumper将默认打开HXPP_CHECK_POINTER,作为其include.xml的一部分,并将为HXCPP的错误和openfl/lime的未捕获错误事件设置挂钩(
我想这可以归结为C++如何处理空指针异常。事实并非如此!
更多信息请点击此处或此处
这似乎很奇怪,有些问题可能有助于解决它。
- 看起来您对xml的外观做了一些假设(做了一些手动
it.next()
(,为什么 - 你为什么要用这个大屁股试接球块
- getNodeNamed看起来怎么样,似乎可以返回
null
- 你有一个示例xml可以测试吗
相关文章:
- 编译器是否必须始终删除 try-catch 块(如果它被证明是非抛出的)
- 有没有更好的方法来处理异常? try-catch块真的很丑
- 我可以使用 try catch 语句来捕获任何错误而不是具体错误吗?
- 在大型应用程序的main上使用try-catch
- RapidXML 节点在 try catch 块中具有正确的值,但它在块外为 nullptr
- 提取 try-catch 时出现运行时错误
- std::unique_ptr 在 try-catch 块中未捕获取消引用异常
- 何时删除 try-catch 块中的指针
- 是否有理由大多数/所有 try-catch 示例只对 throw 语句使用 void 子函数
- 循环try..catch ..确保输入有效或使用控制语句
- 构造函数中的异常:init() 方法、指针、大型 try/catch 或
- C++ C2509 在讲师的定义中使用 try: - catch
- 为什么未达到的 try-catch 块会增加运行时时间
- 在 C++ 中使用 try-catch 进行删除 [] 或删除操作是否必要
- ex.nested try-catch中的什么()更改
- 为什么 c++ try-catch 块不能在 ubuntu 上与 g++ 一起使用?
- 格式化文件异常被 try catch 块忽略
- libpng错误不会被try/catch块捕获
- 在 C++ 和 C# 中使用 try/catch 的正确方法是什么?
- 当使用C++目标的释放模式时,为什么这个Haxe try-catch块仍然崩溃