The code responsible for generating the trace back is in sublime_plugin.py
; whenever it executes user code it catches any unhandled exceptions and then displays the trace back.
You could modify your copy of sublime_plugin
to not display the trace back when exceptions are caught (unwise for a variety of reasons and probably not something you’re going to get your package users to do).
Another way to go would be to wrap the top level of your code in an exception handling block that eats the exception:
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
try:
raise ValueError()
except:
pass
Or if you had a bunch of commands that you wanted to do this for, you could delegate to a parent class to do the exception handling for you so you only have to do it once and it works everywhere transparently:
import sublime
import sublime_plugin
class ExceptionCatchingTextCommand(sublime_plugin.TextCommand):
def run_(self, edit_token, args):
try:
super().run_(edit_token, args)
except:
print("Not on my watch!")
class ExampleCommand(ExceptionCatchingTextCommand):
def run(self, edit, item):
print("Example says %s" % item)
item = item + 12
raise ValueError()
print("Unprinted")
However in this case, you could just call return
from your command or event listener and structure your code accordingly (like returning a boolean “no more runtime for you” for example).
More to the point, masking exceptions means that exceptions are masked. So for the second example, call the command without an item
argument and all you see in the console is “Not on my watch!”. If you actually pass an argument, you see it printed, along with the text “Not on my watch!”. What made it say that? Hard to say (for more complicated code); there’s no exception trace back to tell you where and what went wrong.
If your plugin is doing stuff only when Sublime starts (or you want to stop it from originally loading), perhaps you could implement plugin_loaded
and invoke your top level logic from there, or set a flag that commands and event listeners can check to see if they should do anything or not.