~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to swig/include/python/python_exceptions.i

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 */
6
6
%{
7
7
int bUseExceptions=0;
 
8
CPLErrorHandler pfnPreviousHandler = CPLDefaultErrorHandler;
8
9
 
9
10
void CPL_STDCALL 
10
 
VeryQuietErrorHandler(CPLErr eclass, int code, const char *msg ) 
 
11
PythonBindingErrorHandler(CPLErr eclass, int code, const char *msg ) 
11
12
{
 
13
  /* 
 
14
  ** Generally we want to supress error reporting if we have exceptions
 
15
  ** enabled as the error message will be in the exception thrown in 
 
16
  ** Python.  
 
17
  */
 
18
 
12
19
  /* If the error class is CE_Fatal, we want to have a message issued
13
20
     because the CPL support code does an abort() before any exception
14
21
     can be generated */
15
22
  if (eclass == CE_Fatal ) {
16
 
    CPLDefaultErrorHandler(eclass, code, msg );
 
23
    pfnPreviousHandler(eclass, code, msg );
 
24
  }
 
25
 
 
26
  /*
 
27
  ** We do not want to interfere with warnings or debug messages since
 
28
  ** they won't be translated into exceptions.
 
29
  */
 
30
  if (eclass == CE_Warning || eclass == CE_Debug ) {
 
31
    pfnPreviousHandler(eclass, code, msg );
17
32
  }
18
33
}
19
34
%}
20
35
 
21
36
%inline %{
 
37
 
 
38
int GetUseExceptions() {
 
39
  return bUseExceptions;
 
40
}
 
41
 
22
42
void UseExceptions() {
23
43
  bUseExceptions = 1;
24
 
  CPLSetErrorHandler( (CPLErrorHandler) VeryQuietErrorHandler );
 
44
  pfnPreviousHandler = 
 
45
    CPLSetErrorHandler( (CPLErrorHandler) PythonBindingErrorHandler );
25
46
}
26
47
 
27
48
void DontUseExceptions() {
28
49
  bUseExceptions = 0;
29
 
  CPLSetErrorHandler( CPLDefaultErrorHandler );
 
50
  CPLSetErrorHandler( pfnPreviousHandler );
30
51
}
31
52
%}
32
53
 
34
55
 
35
56
%exception {
36
57
 
 
58
    if ( bUseExceptions ) {
 
59
        CPLErrorReset();
 
60
    }
37
61
    $action
38
62
    if ( bUseExceptions ) {
39
63
      CPLErr eclass = CPLGetLastErrorType();
42
66
      }
43
67
    }
44
68
}
 
69