Hi, everyone. I'm developing a desktop gui app, which is using an external library FANN (with source code). The problem is that I don't know how to catch exceptions which happen in that library. Whatever goes wrong when I invoke external functions crashes my app. So far I tried something like this:
Qt Code:
  1. bool MainWindow::RunFann() {
  2. try {
  3. QDebugStream qds (std::cout,ui->textEdit);
  4.  
  5. if ((ui->lineEdit_4->text() == "") || (ui->lineEdit_5->text() == "")) {
  6. QMessageBox::warning(this,tr("Warning"),tr("Select a valid test data file and a trainded FANN file first!"));
  7. return(false);
  8. }
  9.  
  10. RedirectOutput(0);
  11.  
  12. QByteArray ba = ui->lineEdit_5->text().toLocal8Bit();
  13. struct fann *ann = fann_create_from_file(ba.data());
  14.  
  15. ba = ui->lineEdit_4->text().toLocal8Bit();
  16. struct fann_train_data *TestData = fann_read_train_from_file(ba.data()); //< external lib function call
  17.  
  18. fann_type *result;
  19. printf("SEQUENCE : SOURCE : CALCULATED\n");
  20. for (int i=0;i<TestData->num_data;i++) {
  21. result = fann_run(ann,TestData->input[i]); //< external lib function call
  22. for (int j=0;j<ann->num_output;j++) {
  23. char str[10];
  24. sprintf(str,"%d %s %f %s %f\n",i,":",result[j],":",TestData->output[i][j]);
  25. printf(str);
  26. }
  27. }
  28. RedirectOutput(1);
  29. } catch (std::exception & e) {
  30. printf("something weired happened..");
  31. }
  32.  
  33. }
To copy to clipboard, switch view to plain text mode 
Any help much appreciated.