Hello!

I have a question on how to catch errors if a return-value is not accessible. I am unsure which is a good way to make sure, that a correct value is returned and what to do, if that value is not available.

The function is used to fetch values from a QDialog, called on exec().

Qt Code:
  1. QSqlRecord SelectAddress::passRecord()
  2. {
  3. //check if something is selected
  4. if(tableView->selectionModel()->hasSelection())
  5. {
  6. QModelIndex index = tableView->currentIndex();
  7. if (index.isValid())
  8. {
  9. QSqlRecord record = modelCustomer->record(index.row());
  10. return record;
  11. }
  12. }
  13. else
  14. {
  15. QMessageBox::warning(0, QObject::tr("Selection error"),"No entry selected");
  16. //application crashes here, what should be returned?
  17. }
To copy to clipboard, switch view to plain text mode 

A point into the right direction would be enough.

Kind regards,
HomeR