Julho 06
Prof(s). Eduardo Bezerra & Ismael H. F. Santos                                                2
Comparação de código sem Tratamento e código com Tratatamento de Exceção
nerrorCodeType readFile {
n  initialize errorCode = 0;
n  open the file;
n  if ( theFileIsOpen ) {
n    determine the length of the file;
n    if (gotTheFileLength) {
n      allocate that much memory;
n      if (gotEnoughMemory) {
n        read the file into memory;
n        if (readFailed) errorCode= -1;
n      } else errorCode = -2;
n    } else {
n      errorCode = -3;
n    }
n    close the file;
n    if(fileDidntClose && errorCode==0) {
n      errorCode = -4;
n    } else {
n      errorCode = errorCode and -4;
n    }
n  } else { errorCode = -5; }
n  return errorCode;
n}
nvoid readFile {
n  try {
n    open the file;
n    determine its size;
n    allocate that much memory;
n    read the file into memory;
n    close the file;
n  } catch (fileOpenFailed) {
n    doSomething;
n  } catch (sizeDeterminationFailed) {
n    doSomething;
n  } catch (memoryAllocationFailed) {
n    doSomething;
n  } catch (readFailed) {
n    doSomething;
n  } catch (fileCloseFailed) {
n   doSomething;
n  }
n}