Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions AutoDuck/makedfromi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def make_doc_summary(inFile, outFile):
curMethod[1].append("// " + doc + "\n")
else:
extra_tags.append("// " + doc + "\n")
except:
_, msg, _ = sys.exc_info()
print("Line %d is badly formed - %s" % (lineNo, msg))
except Exception as msg:
print(f"Line {lineNo} is badly formed - {msg}")

lineNo += 1

Expand Down Expand Up @@ -150,10 +149,9 @@ def doit():
elif o == "-o":
outName = a
msg = " ".join(args)
except getopt.error:
_, msg, _ = sys.exc_info()
except getopt.error as msg:
print(msg)
print("Usage: %s [-o output_name] [-p com_parent] filename" % sys.argv[0])
print(f"Usage: {sys.argv[0]} [-o output_name] [-p com_parent] filename")
return

inName = args[0]
Expand Down
6 changes: 2 additions & 4 deletions Pythonwin/pywin/Demos/app/basictimerapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ def OnTimer(self, id, timeVal):
try:
exec(self.dlg.doWork)
print("The last operation completed successfully.")
except:
t, v, tb = sys.exc_info()
str = f"Failed: {t}: {v!r}"
except Exception as error:
str = f"Failed: {type(error)}: {error!r}"
print(str)
self.oldErr.write(str)
tb = None # Prevent cycle
finally:
self.ReleaseOutput()
self.dlg.butOK.EnableWindow()
Expand Down
10 changes: 2 additions & 8 deletions Pythonwin/pywin/Demos/cmdserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,15 @@ def ServerThread(myout, cmd, title, bCloseOnEnd):
if bOK:
print("Command terminated without errors.")
else:
t, v, tb = sys.exc_info()
print(t, ": ", v)
traceback.print_tb(tb)
tb = None # prevent a cycle
traceback.print_exc()
print("Command terminated with an unhandled exception")
writer.unregister()
if bOK and bCloseOnEnd:
myout.frame.DestroyWindow()

# Unhandled exception of any kind in a thread kills the gui!
except:
t, v, tb = sys.exc_info()
print(t, ": ", v)
traceback.print_tb(tb)
tb = None
traceback.print_exc()
print("Thread failed")


Expand Down
6 changes: 2 additions & 4 deletions Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,8 @@ def RespondDebuggerState(self, state):
val = repr(eval(text, globs, locs))
except SyntaxError:
val = "Syntax Error"
except:
t, v, tb = sys.exc_info()
val = traceback.format_exception_only(t, v)[0].strip()
tb = None # prevent a cycle.
except Exception as error:
val = traceback.format_exception_only(type(error), error)[0].strip()
self.SetItemText(i, 1, val)


Expand Down
5 changes: 2 additions & 3 deletions Pythonwin/pywin/debugger/fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# It does nothing useful, and it even doesn't do that!

import sys
import time

import pywin.debugger
Expand All @@ -15,9 +14,9 @@ def a():
a = 1
try:
b()
except:
except Exception as error:
# Break into the debugger with the exception information.
pywin.debugger.post_mortem(sys.exc_info()[2])
pywin.debugger.post_mortem(error.__traceback__)
a = 1
a = 2
a = 3
Expand Down
42 changes: 21 additions & 21 deletions Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ def OnHelp(self, id, code):
from . import help

help.OpenHelpFile(helpFile, helpCmd)
except:
t, v, tb = sys.exc_info()
win32ui.MessageBox(f"Internal error in help file processing\r\n{t}: {v}")
tb = None # Prevent a cycle
except Exception as error:
win32ui.MessageBox(
f"Internal error in help file processing\r\n{type(error)}: {error}"
)

def DoLoadModules(self, modules):
# XXX - this should go, but the debugger uses it :-(
Expand Down Expand Up @@ -280,23 +280,23 @@ def OnDropFiles(self, msg):
# but handles errors slightly better.
# It all still works, tho, so if you need similar functionality, you can use it.
# Therefore I haven't deleted this code completely!
# def CallbackManager( self, ob, args = () ):
# """Manage win32 callbacks. Trap exceptions, report on them, then return 'All OK'
# to the frame-work. """
# import traceback
# try:
# ret = apply(ob, args)
# return ret
# except:
# # take copies of the exception values, else other (handled) exceptions may get
# # copied over by the other fns called.
# win32ui.SetStatusText('An exception occured in a windows command handler.')
# t, v, tb = sys.exc_info()
# traceback.print_exception(t, v, tb.tb_next)
# try:
# sys.stdout.flush()
# except (NameError, AttributeError):
# pass
# def CallbackManager(self, ob, args=()):
# """Manage win32 callbacks. Trap exceptions, report on them, then return 'All OK'
# to the frame-work."""
# try:
# ret = apply(ob, args)
# return ret
# except Exception as error:
# import traceback
#
# # take copies of the exception values, else other (handled) exceptions may get
# # copied over by the other fns called.
# win32ui.SetStatusText("An exception occurred in a windows command handler.")
# traceback.print_exception(type(error), error, error.__traceback__.tb_next)
# try:
# sys.stdout.flush()
# except (NameError, AttributeError):
# pass

# Command handlers.
def OnFileMRU(self, id, code):
Expand Down
66 changes: 35 additions & 31 deletions Pythonwin/pywin/framework/editor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,41 @@
def LoadDefaultEditor():
pass


## prefModule = GetDefaultEditorModuleName()
## restorePrefModule = None
## mod = None
## if prefModule:
## try:
## mod = __import__(prefModule)
## except 'xx':
## msg = "Importing your preferred editor ('%s') failed.\n\nError %s: %s\n\nAn attempt will be made to load the default editor.\n\nWould you like this editor disabled in the future?" % (prefModule, sys.exc_info()[0], sys.exc_info()[1])
## rc = win32ui.MessageBox(msg, "Error importing editor", win32con.MB_YESNO)
## if rc == win32con.IDNO:
## restorePrefModule = prefModule
## WriteDefaultEditorModule("")
## del rc
##
## try:
## # Try and load the default one - don't catch errors here.
## if mod is None:
## prefModule = "pywin.framework.editor.color.coloreditor"
## mod = __import__(prefModule)
##
## # Get at the real module.
## mod = sys.modules[prefModule]
##
## # Do a "from mod import *"
## globals().update(mod.__dict__)
##
## finally:
## # Restore the users default editor if it failed and they requested not to disable it.
## if restorePrefModule:
## WriteDefaultEditorModule(restorePrefModule)
# prefModule = GetDefaultEditorModuleName()
# restorePrefModule = None
# mod = None
# if prefModule:
# try:
# mod = __import__(prefModule)
# except Exception as error:
# msg = (
# f"Importing your preferred editor ('{prefModule}') failed."
# + f"\n\nError {type(error)}: {error}"
# + "\n\nAn attempt will be made to load the default editor."
# + "\n\nWould you like this editor disabled in the future?"
# )
# rc = win32ui.MessageBox(msg, "Error importing editor", win32con.MB_YESNO)
# if rc == win32con.IDNO:
# restorePrefModule = prefModule
# WriteDefaultEditorModule("")
# del rc
#
# try:
# # Try and load the default one - don't catch errors here.
# if mod is None:
# prefModule = "pywin.framework.editor.color.coloreditor"
# mod = __import__(prefModule)
#
# # Get at the real module.
# mod = sys.modules[prefModule]
#
# # Do a "from mod import *"
# globals().update(mod.__dict__)
#
# finally:
# # Restore the users default editor if it failed and they requested not to disable it.
# if restorePrefModule:
# WriteDefaultEditorModule(restorePrefModule)


def GetEditorOption(option, defaultValue, min=None, max=None):
Expand Down
7 changes: 2 additions & 5 deletions Pythonwin/pywin/framework/editor/vss.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


import os
import sys
import traceback

import win32api
Expand Down Expand Up @@ -96,9 +95,7 @@ def CheckoutFile(fileName):
ok = 1
except pythoncom.com_error as exc:
win32ui.MessageBox(exc.strerror, "Error checking out file")
except:
typ, val, tb = sys.exc_info()
except Exception as error:
traceback.print_exc()
win32ui.MessageBox(f"{typ} - {val}", "Error checking out file")
tb = None # Cleanup a cycle
win32ui.MessageBox(f"{type(error)} - {error}", "Error checking out file")
return ok
4 changes: 1 addition & 3 deletions Pythonwin/pywin/framework/intpydde.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# is open. Strange, but true. If you have problems with this, close all Command Prompts!


import sys
import traceback

import win32ui
Expand All @@ -29,10 +28,9 @@ def Exec(self, data):
# print("Executing", cmd)
self.app.OnDDECommand(data)
except:
t, v, tb = sys.exc_info()
# The DDE Execution failed.
print("Error executing DDE command.")
traceback.print_exception(t, v, tb)
traceback.print_exc()
return 0


Expand Down
3 changes: 1 addition & 2 deletions Pythonwin/pywin/framework/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def JumpToDocument(fileName, lineno=0, col=1, nChars=0, bScrollToTop=0):


def _HandlePythonFailure(what, syntaxErrorPathName=None):
typ, details, tb = sys.exc_info()
details = sys.exc_info()[1]
if isinstance(details, SyntaxError):
try:
msg, (fileName, line, col, text) = details
Expand All @@ -616,7 +616,6 @@ def _HandlePythonFailure(what, syntaxErrorPathName=None):
else:
traceback.print_exc()
win32ui.SetStatusText(f"Failed to {what} - {details}")
tb = None # Clean up a cycle.


# Find the Python TabNanny in either the standard library or the Python Tools/Scripts directory.
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/scintilla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ def _AutoComplete(self):
self._UpdateWithITypeInfo(items_dict, typeInfo)
except:
pass
except:
except Exception as error:
win32ui.SetStatusText(
f"Error attempting to get object attributes - {sys.exc_info()[0]!r}"
f"Error attempting to get object attributes - {type(error)!r}"
)

items = [
Expand Down
7 changes: 2 additions & 5 deletions Pythonwin/pywin/tools/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# >>> browser.Browse()
# or
# >>> browser.Browse(your_module)
import sys
import types

import __main__
Expand Down Expand Up @@ -340,10 +339,8 @@ def OnInitDialog(self):
self.edit = self.GetDlgItem(win32ui.IDC_EDIT1)
try:
strval = str(self.object)
except:
t, v, tb = sys.exc_info()
strval = f"Exception getting object value\n\n{t}:{v}"
tb = None
except Exception as error:
strval = f"Exception getting object value\n\n{type(error)}:{error}"
strval = re.sub(r"\n", "\r\n", strval)
self.edit.ReplaceSel(strval)

Expand Down
4 changes: 1 addition & 3 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import copy
import decimal
import os
import sys
import weakref

from . import ado_consts as adc, apibase as api, process_connect_string
Expand Down Expand Up @@ -335,7 +334,7 @@ def close(self):
try:
self._closeAdoConnection() # v2.1 Rose
except Exception as e:
self._raiseConnectionError(sys.exc_info()[0], sys.exc_info()[1])
self._raiseConnectionError(type(e), e)

self.connector = None # v2.4.2.2 fix subtle timeout bug
# per M.Hammond: "I expect the benefits of uninitializing are probably fairly small,
Expand Down Expand Up @@ -855,7 +854,6 @@ def _buildADOparameterList(self, parameters, sproc=False):
except api.Error:
if verbose:
print("ADO Parameter Refresh failed")
pass
else:
if len(parameters) != self.cmd.Parameters.Count - 1:
raise api.ProgrammingError(
Expand Down
5 changes: 2 additions & 3 deletions adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,8 @@ def __getitem__(self, key): # used for row[key] type of value access
return self._getValue(
self.rows.columnNames[key.lower()]
) # extension row[columnName] designation
except (KeyError, TypeError):
er, st, tr = sys.exc_info()
raise er(f'No such key as "{key!r}" in {self!r}').with_traceback(tr)
except (KeyError, TypeError) as er:
raise type(er)(f'No such key as "{key!r}" in {self!r}') from er

def __iter__(self):
return iter(self.__next__())
Expand Down
8 changes: 2 additions & 6 deletions com/win32com/client/gencache.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,8 @@ def Rebuild(verbose=1):
print("Checking", GetGeneratedFileName(*info))
try:
AddModuleToCache(iid, lcid, major, minor, verbose, 0)
except:
print(
"Could not add module {} - {}: {}".format(
info, sys.exc_info()[0], sys.exc_info()[1]
)
)
except Exception as error:
print(f"Could not add module {info} - {type(error)}: {error}")
if verbose and len(infos): # Don't bother reporting this when directory is empty!
print("Done.")
_SaveDicts()
Expand Down
4 changes: 1 addition & 3 deletions com/win32com/client/makepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,8 @@ def GetTypeLibsForSpec(arg):
spec.lcid = attr[1]
typelibs.append((tlb, spec))
return typelibs
except pythoncom.com_error:
t, v, tb = sys.exc_info()
except pythoncom.com_error as v:
sys.stderr.write(f"Unable to load type library from '{arg}' - {v}\n")
tb = None # Storing tb in a local is a cycle!
sys.exit(1)


Expand Down
Loading