ArrayIndexOutOfBoundsException不被捕获和忽略 [英] ArrayIndexOutOfBoundsException not being caught and ignored
问题描述
我想抓住并忽略和ArrayIndexOutOfBoundsException错误(基本上这不是我可以控制的,所以我需要我的程序来保持紧张)。
然而,我的try / catch对似乎没有捕获异常并忽略它。希望你可以选择我做错了什么。
此行发生异常
content = extractor.getTextFromPage(page);
这是我的代码:
$ b (int page = 1; page< = noPages; page ++){try {
System.out.println(page );
content = extractor.getTextFromPage(page);
}
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println(此页面无法读取);
}
}
线程中的异常主要java.lang.ArrayIndexOutOfBoundsException:无效的索引:02
在com.lowagie.text.pdf.CMapAwareDocumentFont.decodeSingleCID(未知来源)
在com.lowagie.text.pdf.CMapAwareDocumentFont.decode(未知来源)
在com.lowagie.text.pdf.parser.PdfContentStreamProcessor.decode(未知来源)
在com.lowagie.text.pdf.parser.PdfContentStreamProcessor.displayPdfString(未知来源)
在com.lowagie.text.pdf.parser.PdfContentStreamProcessor $ ShowText.invoke(未知来源)
在com.lowagie.text.pdf.parser.PdfContentStreamProcessor.invokeOperator(未知来源)
在com.lowagie .com.pdf.parser.PdfContentStreamProcessor.processContent (Extractor.java:64)
编辑: e将try / catch放在for循环中
并添加堆栈跟踪
并删除index = 1
愚蠢的问题,但是您是否将ArrayIndexOutOfBoundsException放在与所抛出的包相同的包中的catch中?即java.lang
或者也可以抓住可以看出是否有效。
I want to catch and ignore and ArrayIndexOutOfBoundsException error (basically it's not something I have control over, so I need my program to keep chugging along).
However my try/catch pair doesn't seem to catch the exception and ignore it. Hopefully you can pick out what I am doing wrong.
The exception occurs at this line
content = extractor.getTextFromPage(page);
Here is my code:
for(int page=1;page<=noPages;page++){
try{
System.out.println(page);
content = extractor.getTextFromPage(page);
}
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("This page can't be read");
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Invalid index: 02 at com.lowagie.text.pdf.CMapAwareDocumentFont.decodeSingleCID(Unknown Source) at com.lowagie.text.pdf.CMapAwareDocumentFont.decode(Unknown Source) at com.lowagie.text.pdf.parser.PdfContentStreamProcessor.decode(Unknown Source) at com.lowagie.text.pdf.parser.PdfContentStreamProcessor.displayPdfString(Unknown Source) at com.lowagie.text.pdf.parser.PdfContentStreamProcessor$ShowText.invoke(Unknown Source) at com.lowagie.text.pdf.parser.PdfContentStreamProcessor.invokeOperator(Unknown Source) at com.lowagie.text.pdf.parser.PdfContentStreamProcessor.processContent(Unknown Source) at com.lowagie.text.pdf.parser.PdfTextExtractor.getTextFromPage(Unknown Source) at com.pdfextractor.main.Extractor.main(Extractor.java:64)
edit: I have put the try/catch within the for loop
and added the stack trace
and removed index=1
Stupid question, but is the ArrayIndexOutOfBoundsException that you put in the catch from the same package as the one being thrown? i.e. java.lang
Or perhaps catch throwable to see if that even works.
这篇关于ArrayIndexOutOfBoundsException不被捕获和忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!