You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2001/06/14 07:25:20 UTC

cvs commit: xml-xerces/perl/Handler PerlExceptionHandler.cpp PerlExceptionHandler.hpp PerlExceptionHandler.swig.hpp

jasons      01/06/13 22:25:20

  Added:       perl/Handler PerlExceptionHandler.cpp
                        PerlExceptionHandler.hpp
                        PerlExceptionHandler.swig.hpp
  Log:
  	* Handler/PerlExceptionHandler.hpp (Repository):
  	Perl class for handling XMLException's
  
  Revision  Changes    Path
  1.1                  xml-xerces/perl/Handler/PerlExceptionHandler.cpp
  
  Index: PerlExceptionHandler.cpp
  ===================================================================
  #include <iostream.h>
  #include "util/PlatformUtils.hpp"
  #include "PerlExceptionHandler.hpp"
  #include "util/XMLString.hpp"
  #include "util/XMLException.hpp"
  
  // we initialize the exceptionHandler
  SV *PerlExceptionHandler::exceptionHandler = NULL;
  
  SV *
  PerlExceptionHandler::setExceptionHandler(SV *codeRef) {
      SV *oldRef = &PL_sv_undef;	// default to 'undef'
      if (SvTYPE( SvRV(codeRef)) == SVt_PVCV) {
  	if (exceptionHandler != NULL) {
  	    oldRef = exceptionHandler;
  	}
          SvREFCNT_inc(codeRef);
          exceptionHandler = codeRef;
      } else {
          cerr << "\nsetExceptionHandler:  "
  	     << "invalid argument, must be code reference.\n" << endl;
      }
      return oldRef;
  }
  
  void 
  PerlExceptionHandler::catchException(const XMLException &e) {
      if (!exceptionHandler) {
  	cerr << "\nReceived Exception without handler\n"
  	     << "Exception thrown in file: '" << e.getSrcFile() << "'\n"
  	     << "At line: '" << e.getSrcLine() << "'\n"
  	     << "Exception message is:  \n"
  	     << XMLString::transcode(e.getMessage()) << "\n" << endl;
  	XMLPlatformUtils::Terminate();
  	die("Received Exception without handler");
      }
      dSP;
  
      ENTER;
      SAVETMPS;
  
      PUSHMARK(SP);
  
          // first argument is the element name
      char *class_name = "XML::Xerces::XMLException";
      HV *hash = newHV();
      HV *stash = gv_stashpv(class_name, FALSE);
      hv_magic(hash, 
      	 (GV *)sv_setref_pv(sv_newmortal(), 
      			    class_name, (void *)&e), 
      	 'P');
      XPUSHs(sv_bless(newRV_noinc((SV *)hash), stash));
      PUTBACK;
  
      perl_call_sv(exceptionHandler, G_VOID);
  
      FREETMPS;
      LEAVE;
  }
  
  
  
  1.1                  xml-xerces/perl/Handler/PerlExceptionHandler.hpp
  
  Index: PerlExceptionHandler.hpp
  ===================================================================
  #ifndef __PERL_EXCEPTION_HANDLER
  #define __PERL_EXCEPTION_HANDLER
  #ifdef __cplusplus
  /* Needed on some windows machines---since MS plays funny
     games with the header files under C++ */
  #include <math.h>
  #include <stdlib.h>
  extern "C" {
  #endif
  #include "EXTERN.h"
  #include "perl.h"
  #include "XSUB.h"
  
  /* Get rid of free and malloc defined by perl */
  #undef free
  #undef malloc
  
  #include <string.h>
  #ifdef __cplusplus
  }
  #endif
  
  #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
  #ifndef PL_sv_yes
  #define PL_sv_yes PL_sv_yes
  #endif
  #ifndef PL_sv_undef
  #define PL_sv_undef PL_sv_undef
  #endif
  #ifndef PL_na
  #define PL_na PL_na
  #endif
  #endif
  
  class XMLException;
  class PerlExceptionHandler {
  
  private:
  
      static SV *exceptionHandler;
      PerlExceptionHandler(void) {};
      virtual ~PerlExceptionHandler(void) = 0;
  
  public:
  
      static SV *setExceptionHandler(SV *codeRef);
      static void catchException(const XMLException &e);
  };
  
  #endif // __PERL_EXCEPTION_HANDLER 
  
  
  
  1.1                  xml-xerces/perl/Handler/PerlExceptionHandler.swig.hpp
  
  Index: PerlExceptionHandler.swig.hpp
  ===================================================================
  class PerlExceptionHandler {
  
  private:
  
  //    SV *exceptionHandler;
  
  public:
  
      void setExceptionHandler(SV *function);
  //    void catchException(const XMLException &e);
  };
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org