标签: error-handling

属性或索引器不能作为out或ref参数传递

我收到上述错误,无法解决.我google了一下,但无法摆脱它.

场景:

我有类BudgetAllocate,其属性是预算,是双重类型.

在我的dataAccessLayer中,

在我的一个课程中,我试图这样做:

double.TryParse(objReader[i].ToString(), out bd.Budget);
Run Code Online (Sandbox Code Playgroud)

这引发了这个错误:

在编译时,属性或索引器不能作为out或ref参数传递.

我甚至试过这个:

double.TryParse(objReader[i].ToString().Equals(DBNull.Value) ? "" : objReader[i].ToString(), out bd.Budget);
Run Code Online (Sandbox Code Playgroud)

其他一切工作正常,层之间的引用存在.

.net c# error-handling

73
推荐指数
6
解决办法
7万
查看次数

处理ANTLR4中的错误

解析器不知道该怎么做的默认行为是将消息打印到终端,如:

第1:23行丢失DECIMAL at'}'

这是一个好消息,但在错误的地方.我宁愿接受这个作为例外.

我已经尝试过使用了BailErrorStrategy,但这会抛出ParseCancellationException没有消息(由a引起InputMismatchException,也没有消息).

有没有办法让我通过异常报告错误,同时保留邮件中的有用信息?


这就是我真正想要的 - 我通常在规则中使用动作来构建对象:

dataspec returns [DataExtractor extractor]
    @init {
        DataExtractorBuilder builder = new DataExtractorBuilder(layout);
    }
    @after {
        $extractor = builder.create();
    }
    : first=expr { builder.addAll($first.values); } (COMMA next=expr { builder.addAll($next.values); })* EOF
    ;

expr returns [List<ValueExtractor> values]
    : a=atom { $values = Arrays.asList($a.val); }
    | fields=fieldrange { $values = values($fields.fields); }
    | '%' { $values = null; }
    | ASTERISK { $values = values(layout); }
    ;
Run Code Online (Sandbox Code Playgroud)

然后当我调用解析器时,我做了类似这样的事情:

public …
Run Code Online (Sandbox Code Playgroud)

java error-handling antlr4

70
推荐指数
3
解决办法
3万
查看次数

Node.js捕获spawn后抛出的ENOMEM错误

由于在使用spawn时抛出了ENOMEM(内存不足)错误,我的Node.js脚本崩溃了.

错误:

child_process.js:935
  throw errnoException(process._errno, 'spawn');
        ^

Error: spawn ENOMEM
  at errnoException (child_process.js:988:11)
  at ChildProcess.spawn (child_process.js:935:11)
  at Object.exports.spawn (child_process.js:723:9)
  at module.exports ([...]/node_modules/zbarimg/index.js:19:23)
Run Code Online (Sandbox Code Playgroud)

我已经在errorexit事件中使用了侦听器,但是如果出现此错误,则不会触发它们.

我的代码:

zbarimg = process.spawn('zbarimg', [photo, '-q']);
zbarimg.on('error', function(err) { ... });
zbarimg.on('close', function(code) { ... }); 
Run Code Online (Sandbox Code Playgroud)

完整源代码可用.

有什么办法可以防止脚本崩溃吗?如何捕获抛出的ENOMEM错误?

谢谢!

javascript error-handling try-catch spawn node.js

70
推荐指数
3
解决办法
4万
查看次数

Python:它有一个argc参数吗?

我用C和C++编写了相同的程序(打开文本文件和显示内容).现在我在Python中做同样的事情(在Linux机器上).

在C程序中,我使用代码if(argc!= 2){//退出程序}

问题:Python中用于检查参数数量的内容

if (argc != 2) {
    /* exit program */
}
Run Code Online (Sandbox Code Playgroud)

当前输出:

./python names.txt =显示文本文件(正确)./ python nam =错误消息:从sys.ext行声明(正确)./ python =错误消息:从sys.ext行声明(错误:想要它是一个单独的错误消息,说明没有文件名输入)

python linux error-handling file-io arguments

69
推荐指数
3
解决办法
9万
查看次数

如何捕获此错误:"注意:未定义的偏移量:0"

我想抓住这个错误:

$a[1] = 'jfksjfks';
try {
      $b = $a[0];
} catch (\Exception $e) {
      echo "jsdlkjflsjfkjl";
}
Run Code Online (Sandbox Code Playgroud)

编辑:事实上,我在以下行中收到此错误: $parse = $xml->children[0]->children[0]->toArray();

php error-handling try-catch

67
推荐指数
4
解决办法
8万
查看次数

检查localStorage是否可用

我知道有很多关于检查的问题localStorage但是如果有人在浏览器中手动关闭它会怎么样?这是我用来检查的代码:

localStorage.setItem('mod', 'mod');
if (localStorage.getItem('mod') != null){
  alert ('yes');
  localStorage.removeItem('mod');
} else {
  alert ('no');
}
Run Code Online (Sandbox Code Playgroud)

功能简单,有效.但是,如果我进入我的Chrome设置并选择"不保存数据"选项(我不记得它的确切名称),当我尝试运行此功能时,我什么也得不到Uncaught Error: SecurityError: DOM Exception 18.那么有没有办法检查这个人是否完全关闭了?

更新:这是我尝试的第二个功能,我仍然没有得到任何响应(警报).

try {
  localStorage.setItem('name', 'Hello World!');
} catch (e) {
  if (e == QUOTA_EXCEEDED_ERR) {
   alert('Quota exceeded!');
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript error-handling local-storage

67
推荐指数
5
解决办法
7万
查看次数

如何将iPhone OSStatus代码转换为有用的东西?

我对这款iPhone SDK及其文档感到有点不舒服......

我打电话给AudioConverterNew

在返回下的文档中:它说"返回状态代码"......真的......

到目前为止,通过玩这些参数我只能得到两个不同的错误,这两个错误都没有列在音频转换器参考的底部.

它们是'mrep'和'?tmf'(将OSStatus转换为char数组)但具体代码并不是真正重要的.

据我所知,随机错误代码是在随机文件中定义的,因此您不能只搜索一个文件,我找不到只是让您搜索错误代码以获取更多信息的帮助文档,并且我可以告诉你,在OS X中,你可以使用GetMacOSStatusErrorString()将错误转换为有用的东西,但没有iPhone等价?

任何帮助将不胜感激.

编辑:

好的,所以投射它们反过来(我检查'mrep',但不是那里的任何一种方式),fmt?在音频转换器api的列表中,如果有点模糊,但是很公平,仍然'perm'不存在(尽管它可能与模拟器不支持aac解码有关)和我的一般问题仍然存在.

macos error-handling cocoa cocoa-touch ios

65
推荐指数
9
解决办法
4万
查看次数

在远程shell中使用Fabric进行run()调用时,是否可以捕获错误代码?

通常,只要run()调用返回非零退出代码,Fabric就会退出.但是,对于某些电话,这是预期的.例如,PNGOut在无法压缩文件时返回错误代码2.

目前我只能通过使用shell逻辑(do_something_that_fails || truedo_something_that_fails || do_something_else)来绕过这个限制,但我宁愿能够将我的逻辑保存在普通的Python中(就像Fabric承诺一样).

有没有办法检查错误代码并对其做出反应而不是让Fabric出现恐慌并死掉?我仍然想要其他调用的默认行为,因此通过修改环境来改变它的行为似乎不是一个好的选择(据我所知,你只能使用它来告诉它警告而不是死亡).

python error-handling fabric

64
推荐指数
2
解决办法
4万
查看次数

Swift中的throws和rethrows有什么区别?

寻找一些参考资料后弄明白,-unfortunately-我找不到任何关于理解之间的差异有用-和简单-描述throwsrethrows.当试图理解我们应该如何使用它时,这有点令人困惑.

我想提一下,我对-default-熟悉throws传播错误的最简单形式,如下所示:

enum CustomError: Error {
    case potato
    case tomato
}

func throwCustomError(_ string: String) throws {
    if string.lowercased().trimmingCharacters(in: .whitespaces) == "potato" {
        throw CustomError.potato
    }

    if string.lowercased().trimmingCharacters(in: .whitespaces) == "tomato" {
        throw CustomError.tomato
    }
}

do {
    try throwCustomError("potato")
} catch let error as CustomError {
    switch error {
    case .potato:
        print("potatos catched") // potatos catched
    case .tomato:
        print("tomato catched")
    }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止一直很好,但问题出现在:

func throwCustomError(function:(String) throws -> ()) throws {
    try function("throws string") …
Run Code Online (Sandbox Code Playgroud)

error-handling try-catch rethrow throws swift

64
推荐指数
2
解决办法
1万
查看次数

如何在PHP中启用错误报告?

我最近将我的网站从共享服务器移动到我自己的服务器.现在,当我遇到PHP错误时,我收到500内部服务器错误.在我的老东道主,我会得到类似"致命错误:期待;"的内容.我如何启用它?

php error-handling

62
推荐指数
0
解决办法
13万
查看次数