在什么情况下应该抓住java.lang.Error应用程序?
对于正在盯着学习Java的c#开发人员来说,应该指出两种语言之间存在哪些重大差异?
也许有些人可能认为事情是一样的,但是有一些不容忽视的导入方面?(或者你真的搞砸了!)
也许就OOP结构,GC的工作方式,引用,部署相关等而言.
我有一个生成以下异常的代码:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at edu.createArrays(ExhaustivePCFGParser.java:2188)
at edu.considerCreatingArrays(ExhaustivePCFGParser.java:2158)
at edu.ExhaustivePCFGParser.parse(ExhaustivePCFGParser.java:339)
at edu.LexicalizedParserQuery.parse(LexicalizedParserQuery.java:247)
at edu.LexicalizedParser.apply(LexicalizedParser.java:283)
at current.Gen.textParsen(Gen.java:162)
at current.Gen.gen(Gen.java:90)
at current.Foo.main(Foo.java:120)
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码捕获它:
try {
// this is the line which cause the exception
LinkedList<Foo> erg = Gen.gen(rev);
} catch (Exception e) {
System.out.println("exception: out of memory");
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行代码时,异常没有被捕获.怎么解决这个?