0

Possible Duplicate:
To throw or not to throw exceptions?

For example, in some code like this,

int Type1::LoadFile(QString filePath)
{
    QFile infile(filePath);
    if (!infile.open(QIODevice::ReadOnly | QIODevice::Text))
        return 1 or throw some exception;
    QTextStream in(&

What should I do, return 1(which means open file failed) or throw some FileLoadErrorException?

Thanks.

Community
  • 1
  • 1
Jichao
  • 38,362
  • 43
  • 118
  • 192
  • Depends on what you need to do if the error occurs. Is it something that is best handled locally, something that can't be handled at all, and requires the application to exit, or something that can be handled higher up the call tree? – jalf Jan 01 '12 at 17:18
  • See http://stackoverflow.com/questions/253314/exceptions-or-error-codes – Seth Carnegie Jan 01 '12 at 17:19
  • And be very careful with mixing exceptions with Qt, they're not really well supported or encouraged AFAIK. See http://developer.qt.nokia.com/doc/qt-4.8/exceptionsafety.html . – Mat Jan 01 '12 at 17:22

0 Answers0