home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / exceptns / exviewer / exviewer.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  2.5 KB  |  84 lines

  1. //************************************************************
  2. // Error Reporting - Exception Viewer Example
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <iapp.hpp>
  9. #include <imsgbox.hpp>
  10. #include <icconst.h>
  11. #include "exviewer.hpp"
  12. #include "exviewer.h"
  13.  
  14. ExceptionViewer::ExceptionViewer ( )
  15.        : frameWindow(IFrameWindow::defaultStyle() | 
  16.                      IFrameWindow::menuBar,
  17.                      WND_MAIN),
  18.          mleWindow(IC_FRAME_CLIENT_ID, &frameWindow, &frameWindow),
  19.          menuHandler(*this)
  20. {
  21.    IException::setTraceFunction(*this);
  22.    IWindow::setExceptionFunction(this);
  23.    mle().disableDataUpdate();
  24.    menuHandler.handleEventsFor(&frame());
  25.  
  26.    frame()
  27.     .setClient(&mle())
  28.     .setFocus()
  29.     .show();
  30. }
  31.  
  32. Boolean MenuHandler::command(ICommandEvent& event)
  33. {
  34.   switch (event.commandId()) {
  35.      case THROW_EXCEPTION:
  36.         IException exc("\nException thrown from menu selection.  \n",
  37.                        0, IException::recoverable);
  38.         ITHROW(exc);
  39.   }                                 
  40.   return false;                      
  41.  
  42. void ExceptionViewer::write ( const char* buffer )
  43. {
  44.    mle().addAsLast((char*)buffer);
  45. }
  46.  
  47. Boolean ExceptionViewer::handleException (IException& exc, IEvent& event)
  48. {
  49.    IMessageBox msgBox(&frame());
  50.    msgBox.setTitle("Exception caught in dispatch routine");
  51.    IMessageBox::Response response =
  52.       msgBox.show(exc.text(),
  53.                   IMessageBox::retryCancelButton |
  54.                   IMessageBox::errorIcon         |
  55.                   IMessageBox::moveable );
  56.    if (response == IMessageBox::retry) {
  57.       mle().addAsLast("Exception caught in dispatch.  User decided to retry.\n",
  58.                        0, IMultiLineEdit::noTran );
  59.       return true;
  60.    }
  61.    else {
  62.       exc.setText("Exception caught and rethrown in dispatch.  User decided to cancel.");
  63.       IRETHROW(exc);
  64.    }
  65. }
  66.  
  67. void main()
  68. {
  69.    ExceptionViewer mainWindow;
  70.    try {                                        
  71.       IApplication::current().run();
  72.    }
  73.    catch ( IException& exc) {  
  74.       IMessageBox msgBox(&mainWindow.frame());
  75.       msgBox.setTitle("Exception caught in Main routine");
  76.       msgBox.show(exc.text(),
  77.                   IMessageBox::okButton    |
  78.                   IMessageBox::errorIcon   |
  79.                   IMessageBox::moveable );
  80.    }
  81.  
  82.