Skip to content

Commit

Permalink
mp_module.py: add convenience print_caught_exception
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Jul 10, 2024
1 parent 7fa0f70 commit 5d9ad13
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion MAVProxy/modules/lib/mp_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from pymavlink import mavutil
import traceback

class MPModule(object):
'''
Expand Down Expand Up @@ -254,4 +255,15 @@ def send_named_float(self, name, value):
self.named_float_seq = (self.named_float_seq+1) % 256
m.name = name
self.mpstate.module('link').master_callback(m, self.master)


def get_exception_stacktrace(self, e):
if sys.version_info[0] >= 3:
ret = "%s\n" % e
ret += ''.join(traceback.format_exception(type(e),
e,
tb=e.__traceback__))
return ret
return traceback.format_exc(e)

def print_caught_exception(self, e):
print(self.get_exception_stacktrace(e))

0 comments on commit 5d9ad13

Please sign in to comment.