roddey      99/11/30 12:23:13

  Modified:    c/src/internal XMLScanner.cpp
  Log:
  Added changes to handle exceptions thrown from the user's handlers for
  emitError().
  
  Revision  Changes    Path
  1.2       +109 -49   xml-xerces/c/src/internal/XMLScanner.cpp
  
  Index: XMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLScanner.cpp    1999/11/09 01:08:22     1.1
  +++ XMLScanner.cpp    1999/11/30 20:23:13     1.2
  @@ -56,9 +56,13 @@
   
   /**
    * $Log: XMLScanner.cpp,v $
  - * Revision 1.1  1999/11/09 01:08:22  twl
  - * Initial revision
  + * Revision 1.2  1999/11/30 20:23:13  roddey
  + * Added changes to handle exceptions thrown from the user's handlers for
  + * emitError().
    *
  + * Revision 1.1.1.1  1999/11/09 01:08:22  twl
  + * Initial checkin
  + *
    * Revision 1.7  1999/11/08 20:56:54  droddey
    * If the main xml entity does not exist, we need to get the error handling 
for that
    * inside the main XMLScanner::scanDocument() try block so that it gets 
reported
  @@ -243,23 +247,31 @@
           // If we have a document handler, then call the end document
           if (fDocHandler)
               fDocHandler->endDocument();
  +
  +        // Reset the reader manager to close all files, sockets, etc...
  +        fReaderMgr.reset();
       }
   
  +    //
  +    //  NOTE:
  +    //
  +    //  In all of the error processing below, the emitError() call MUST come
  +    //  before the flush of the reader mgr, or it will fail because it tries
  +    //  to find out the position in the XML source of the error.
  +    //
       catch(const XML4CErrs::Codes)
       {
  -        // This is a 'first fatal error' type exit, so just fall through
  +        // This is a 'first fatal error' type exit, so reset and fall through
  +        fReaderMgr.reset();
       }
   
  -    //
  -    //  We have to propogate SAX exceptions. Since they are derived from our
  -    //  XMLException class, we have to filter it out first here so that it
  -    //  does not get caught and eaten below.
  -    //
       catch(const SAXException&)
       {
  +        //
  +        //  We have to propogate SAX exceptions.
           //
  -        //  Make sure we do anything that would normally be done on the way
  -        //  out of this method.
  +        //  Make sure that the reader manager gets reset, then rethrow this
  +        //  exception since it means nothing much to us.
           //
           fReaderMgr.reset();
           throw;
  @@ -267,35 +279,38 @@
   
       catch(const XMLException& excToCatch)
       {
  +        //
  +        //  Emit the error and catch any user exception thrown from here. 
Make
  +        //  sure in all cases we flush the reader manager.
  +        //
           fInException = true;
  -        emitError
  -        (
  -            XML4CErrs::XMLException
  -            , excToCatch.getType()
  -            , excToCatch.getMessage()
  -        );
  +        try
  +        {
  +            emitError
  +            (
  +                XML4CErrs::XMLException
  +                , excToCatch.getType()
  +                , excToCatch.getMessage()
  +            );
  +        }
  +
  +        catch(...)
  +        {
  +            // Flush the reader manager and rethrow user's error
  +            fReaderMgr.reset();
  +            throw;
  +        }
   
  -        // And fall through
  +        // If it returned, then reset the reader manager and fall through
  +        fReaderMgr.reset();
       }
   
       catch(...)
       {
  -        //
  -        //  We don't know what happened. So issue an error, flush the reader
  -        //  manager to close down files, sockets, etc... and rethrow.
  -        //
  -        //  NOTE: The error emit MUST come before the flush of the reader
  -        //  or it will fail because it tries to find out the position in
  -        //  the XML source of the error.
  -        //
  -        fInException = true;
  -        emitError(XML4CErrs::SysException);
  +        // Reset and rethrow
           fReaderMgr.reset();
           throw;
       }
  -
  -    // Reset the reader manager to close all files
  -    fReaderMgr.reset();
   }
   
   
  @@ -332,9 +347,16 @@
           scanProlog();
       }
   
  -    // This is a 'first failure' exception so reset and return a failure
  +    //
  +    //  NOTE:
  +    //
  +    //  In all of the error processing below, the emitError() call MUST come
  +    //  before the flush of the reader mgr, or it will fail because it tries
  +    //  to find out the position in the XML source of the error.
  +    //
       catch(const XML4CErrs::Codes)
       {
  +        // This is a 'first failure' exception so reset and return a failure
           fReaderMgr.reset();
           return false;
       }
  @@ -346,24 +368,38 @@
           throw;
       }
   
  -    // This one is just a failure
       catch(const XMLException& excToCatch)
       {
  +        //
  +        //  Emit the error and catch any user exception thrown from here. 
Make
  +        //  sure in all cases we flush the reader manager.
  +        //
           fInException = true;
  -        emitError
  -        (
  -            XML4CErrs::XMLException
  -            , excToCatch.getType()
  -            , excToCatch.getMessage()
  -        );
  +        try
  +        {
  +            emitError
  +            (
  +                XML4CErrs::XMLException
  +                , excToCatch.getType()
  +                , excToCatch.getMessage()
  +            );
  +        }    
  +
  +        catch(...)
  +        {
  +            // Reset and rethrow the user error
  +            fReaderMgr.reset();
  +            throw;
  +        }
  +
  +        // Reset and return a failure
           fReaderMgr.reset();
           return false;
       }
   
       catch(...)
       {
  -        fInException = true;
  -        emitError(XML4CErrs::SysException);
  +        // Reset and rethrow original error
           fReaderMgr.reset();
           throw;
       }
  @@ -451,9 +487,16 @@
           }
       }
   
  -    // This is a 'first failure' exception, so reset and return failure
  +    //
  +    //  NOTE:
  +    //
  +    //  In all of the error processing below, the emitError() call MUST come
  +    //  before the flush of the reader mgr, or it will fail because it tries
  +    //  to find out the position in the XML source of the error.
  +    //
       catch(const XML4CErrs::Codes)
       {
  +        // This is a 'first failure' exception, so reset and return failure
           fReaderMgr.reset();
           return false;
       }
  @@ -461,33 +504,51 @@
       // We have to propogate SAX exceptions
       catch(const SAXException&)
       {
  +        // Just reset our reader manager and rethrow SAX exception
           fReaderMgr.reset();
           throw;
       }
   
  -    // This one is just a failure
       catch(const XMLException& excToCatch)
       {
  +        //
  +        //  Emit the error and catch any user exception thrown from here. 
Make
  +        //  sure in all cases we flush the reader manager.
  +        //
           fInException = true;
  -        emitError
  -        (
  -            XML4CErrs::XMLException
  -            , excToCatch.getType()
  -            , excToCatch.getMessage()
  -        );
  +        try
  +        {
  +            emitError
  +            (
  +                XML4CErrs::XMLException
  +                , excToCatch.getType()
  +                , excToCatch.getMessage()
  +            );
  +        }
  +
  +        catch(...)
  +        {
  +            // REset and rethrow user error
  +            fReaderMgr.reset();
  +            throw;
  +        }
   
  +        // Reset and return failure
           fReaderMgr.reset();
           return false;
       }
   
       catch(...)
       {
  -        fInException = true;
  -        emitError(XML4CErrs::SysException);
  -
  +        // Reset and rethrow original error
           fReaderMgr.reset();
           throw;
       }
  +
  +    // If we hit the end, then flush the reader manager
  +    if (!retVal)
  +        fReaderMgr.reset();
  +
       return retVal;
   }
   
  
  
  

Reply via email to