Skip to content

Commit 7c40fec

Browse files
committed
mp_module.py: add convenience print_caught_exception
1 parent ba6edbe commit 7c40fec

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

MAVProxy/modules/lib/mp_module.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
from pymavlink import mavutil
3+
import traceback
34

45
class MPModule(object):
56
'''
@@ -254,4 +255,15 @@ def send_named_float(self, name, value):
254255
self.named_float_seq = (self.named_float_seq+1) % 256
255256
m.name = name
256257
self.mpstate.module('link').master_callback(m, self.master)
257-
258+
259+
def get_exception_stacktrace(self, e):
260+
if sys.version_info[0] >= 3:
261+
ret = "%s\n" % e
262+
ret += ''.join(traceback.format_exception(type(e),
263+
e,
264+
tb=e.__traceback__))
265+
return ret
266+
return traceback.format_exc(e)
267+
268+
def print_caught_exception(self, e):
269+
print(self.get_exception_stacktrace(e))

0 commit comments

Comments
 (0)