Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2@file 

3 

4@brief defines logged exceptions for SQL requests 

5""" 

6 

7 

8class DBException(Exception): 

9 

10 """ 

11 custom exception 

12 """ 

13 pass 

14 

15 

16class ExceptionSQL(DBException): 

17 

18 """ 

19 exception related to SQL instructions and only them 

20 """ 

21 

22 def __init__(self, description, ex, sql, log=True): 

23 """ 

24 @param description message 

25 @param ex sqlite exception 

26 @param sql SQL instruction 

27 @param log log the exception 

28 """ 

29 DBException.__init__(self, description + "\n" + sql) 

30 self.ex = ex 

31 self.sql = sql 

32 if log: 

33 print(description + "\n" + sql) # pragma: no cover 

34 

35 def __str__(self): 

36 mes = Exception.__str__(self) 

37 mes += "\n" + str(self.ex) 

38 mes += "\n" + "\n".join(repr(self.sql).split("\\n")) 

39 if len(mes) > 10000: 

40 mes = mes[:10000] + "\n..." # pragma: no cover 

41 return mes