@@ -1354,8 +1354,8 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
1354
1354
try :
1355
1355
try :
1356
1356
loc ,tokens = self .parseImpl ( instring , preloc , doActions )
1357
- except IndexError :
1358
- raise ParseException ( instring , len (instring ), self .errmsg , self )
1357
+ except IndexError as e :
1358
+ raise ParseException ( instring , len (instring ), self .errmsg , self ) from e
1359
1359
except ParseBaseException as err :
1360
1360
#~ print ("Exception raised:", err)
1361
1361
if self .debugActions [2 ]:
@@ -1372,8 +1372,8 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
1372
1372
if self .mayIndexError or loc >= len (instring ):
1373
1373
try :
1374
1374
loc ,tokens = self .parseImpl ( instring , preloc , doActions )
1375
- except IndexError :
1376
- raise ParseException ( instring , len (instring ), self .errmsg , self )
1375
+ except IndexError as e :
1376
+ raise ParseException ( instring , len (instring ), self .errmsg , self ) from e
1377
1377
else :
1378
1378
loc ,tokens = self .parseImpl ( instring , preloc , doActions )
1379
1379
@@ -1414,9 +1414,9 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
1414
1414
def tryParse ( self , instring , loc ):
1415
1415
try :
1416
1416
return self ._parse ( instring , loc , doActions = False )[0 ]
1417
- except ParseFatalException :
1418
- raise ParseException ( instring , loc , self .errmsg , self )
1419
-
1417
+ except ParseFatalException as e :
1418
+ raise ParseException ( instring , loc , self .errmsg , self ) from e
1419
+
1420
1420
def canParseNext (self , instring , loc ):
1421
1421
try :
1422
1422
self .tryParse (instring , loc )
@@ -3383,9 +3383,9 @@ def parseImpl( self, instring, loc, doActions=True ):
3383
3383
raise
3384
3384
except ParseBaseException as pe :
3385
3385
pe .__traceback__ = None
3386
- raise ParseSyntaxException ._from_exception (pe )
3387
- except IndexError :
3388
- raise ParseSyntaxException (instring , len (instring ), self .errmsg , self )
3386
+ raise ParseSyntaxException ._from_exception (pe ) from pe
3387
+ except IndexError as e :
3388
+ raise ParseSyntaxException (instring , len (instring ), self .errmsg , self ) from e
3389
3389
else :
3390
3390
loc , exprtokens = e ._parse ( instring , loc , doActions )
3391
3391
if exprtokens or exprtokens .haskeys ():
@@ -5581,7 +5581,7 @@ def cvt_fn(s,l,t):
5581
5581
try :
5582
5582
return datetime .strptime (t [0 ], fmt ).date ()
5583
5583
except ValueError as ve :
5584
- raise ParseException (s , l , str (ve ))
5584
+ raise ParseException (s , l , str (ve )) from ve
5585
5585
return cvt_fn
5586
5586
5587
5587
@staticmethod
@@ -5603,7 +5603,7 @@ def cvt_fn(s,l,t):
5603
5603
try :
5604
5604
return datetime .strptime (t [0 ], fmt )
5605
5605
except ValueError as ve :
5606
- raise ParseException (s , l , str (ve ))
5606
+ raise ParseException (s , l , str (ve )) from ve
5607
5607
return cvt_fn
5608
5608
5609
5609
iso8601_date = Regex (r'(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?' ).setName ("ISO8601 date" )
0 commit comments