@@ -1354,8 +1354,8 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
13541354 try :
13551355 try :
13561356 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
13591359 except ParseBaseException as err :
13601360 #~ print ("Exception raised:", err)
13611361 if self .debugActions [2 ]:
@@ -1372,8 +1372,8 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
13721372 if self .mayIndexError or loc >= len (instring ):
13731373 try :
13741374 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
13771377 else :
13781378 loc ,tokens = self .parseImpl ( instring , preloc , doActions )
13791379
@@ -1414,9 +1414,9 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
14141414 def tryParse ( self , instring , loc ):
14151415 try :
14161416 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+
14201420 def canParseNext (self , instring , loc ):
14211421 try :
14221422 self .tryParse (instring , loc )
@@ -3383,9 +3383,9 @@ def parseImpl( self, instring, loc, doActions=True ):
33833383 raise
33843384 except ParseBaseException as pe :
33853385 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
33893389 else :
33903390 loc , exprtokens = e ._parse ( instring , loc , doActions )
33913391 if exprtokens or exprtokens .haskeys ():
@@ -5581,7 +5581,7 @@ def cvt_fn(s,l,t):
55815581 try :
55825582 return datetime .strptime (t [0 ], fmt ).date ()
55835583 except ValueError as ve :
5584- raise ParseException (s , l , str (ve ))
5584+ raise ParseException (s , l , str (ve )) from ve
55855585 return cvt_fn
55865586
55875587 @staticmethod
@@ -5603,7 +5603,7 @@ def cvt_fn(s,l,t):
56035603 try :
56045604 return datetime .strptime (t [0 ], fmt )
56055605 except ValueError as ve :
5606- raise ParseException (s , l , str (ve ))
5606+ raise ParseException (s , l , str (ve )) from ve
56075607 return cvt_fn
56085608
56095609 iso8601_date = Regex (r'(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?' ).setName ("ISO8601 date" )
0 commit comments