如何找到 scala.MatchError 的来源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31466435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find source of scala.MatchError?
提问by Rubbic
I have a parser program in Scala sending stringto it and breaking the string and parse. I am getting the following error on that which I don't even know which part of the program is wrong:
我在 Scala 中有一个解析器程序发送string给它并破坏字符串和解析。我收到以下错误,我什至不知道程序的哪一部分是错误的:
Exception in thread "main" scala.MatchError: xxxx/xml/test3D.xml (of class java.lang.String)
What are the possibilities that I need to check and what is the best way to solve these kind of errors?
我需要检查哪些可能性以及解决此类错误的最佳方法是什么?
回答by ka4eli
There is exact place where exception occurred and it is described by file name and line number in this file. For example, look at this stack trace:
有确切的异常发生的地方,在这个文件中用文件名和行号来描述。例如,看看这个堆栈跟踪:
Exception in thread "main" scala.MatchError: 7 (of class java.lang.Integer)
at stackoverflow.M$.delayedEndpoint$stackoverflow$M(Functions.scala:35)
at stackoverflow.M$delayedInit$body.apply(Functions.scala:30)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
Here you can see that exception cause is on line 35in Functions.scalafile. The second line in a stack trace is the line where exception was thrown. Check this line!
在这里您可以看到异常原因位于Functions.scala文件的第35行。堆栈跟踪中的第二行是引发异常的行。检查这条线!
MatchError occurs whenever an object doesn't match any pattern of a pattern matching expression.
每当对象与模式匹配表达式的任何模式都不匹配时,就会发生 MatchError。

