0

My app exit while executing an function from ironocr library (ocr.read()) without throw any exceptions although i put the line of code in try catch block, My question is how i throw exception to see the reason of the function failed or skip reading that file and don't exit the app. :

private void SearchPDF(string fileName)
{
    try
    {
        StringBuilder text = new StringBuilder();
        if (new FileInfo(fileName).Length == 0)
        {
            return;
        }

        var Ocr = new IronTesseract();

        Ocr.Language = OcrLanguage.English;
        using (var Input = new OcrInput(fileName))
        {
            var Result = Ocr.Read(Input);
            string currentSubText = Result.Text;
            text.Append(currentSubText);

        }
        string searchWord = "";
        txtSearch.Invoke((MethodInvoker)delegate { searchWord = txtSearch.Text.ToLower(); });
        string fileData = text.ToString();
        string fileNameWithExt = System.IO.Path.GetFileName(fileName);
        if (isIN(fileNameWithExt, fileData, searchWord))
        {
            matchingPdfFiles.Add(fileNameWithExt, fileName);
            fillInTable(fileName);
        }
    }
    catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
}
  • 3
    Show us the try/catch and anything else relevant - we can't guess what's going on. Provide a [mre] of your issue, please. See also [ask]. – ADyson Aug 30 '22 at 09:40
  • Check the event viewer. It is perfectly possible that the OCR library did something bad like segmentation fault that just kills your process, nothing you can do about it, other than ensure your input is correct. – JonasH Aug 30 '22 at 09:50
  • You probably can't. When a library handles an exception unless it throw the exception you have no way of knowing the exception already was captured. The only way you can tell an exception occurred is when the the returned parameters are not correct or contains an error condition. – jdweng Aug 30 '22 at 10:04

0 Answers0