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);
}
}