Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Changing a traceback message without a 2nd raise
#1
1/0
Error:
Traceback (most recent call last): File "C:/Documents/err.py", line 9, in <module> 1/0 ZeroDivisionError: division by zero
I want to change exactly one thing about this stack trace, that message that follows the colon.
I do not want to raise a 2nd Error because I need to preserve the ability to click back through in the shell.

I've tried capturing it:
try:
    1/0
except ZeroDivisionError:
    raise ZeroDivisionError("Don't do that")
But this makes the traceback too complex and the last click back is to the raise, not the actual error.
Error:
Traceback (most recent call last): File "C:/Documents/err.py", line 10, in <module> 1/0 ZeroDivisionError: division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Documents/err.py", line 12, in <module> raise ZeroDivisionError("Don't do that") ZeroDivisionError: Don't do that
I imagine the answer is in the traceback module but I cannot find it.

What I want is:
Error:
Traceback (most recent call last): File "C:/Documents/err.py", line 9, in <module> 1/0 ZeroDivisionError: Don't do that
Quote
#2
Try
try:
    1/0
except ZeroDivisionError as err:
    err.args = ("Don't do that",)
    raise
Clunk_Head likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Changing Data Types BallisticSwami 2 118 Jun-27-2019, 01:17 PM
Last Post: BallisticSwami
  changing format to Int Scott 3 239 Jun-19-2019, 06:33 AM
Last Post: ODIS
  error message on program launch DJPY1175 0 163 Jun-10-2019, 08:40 AM
Last Post: DJPY1175
  I am trying to send message in youtube live chat stylohunk 1 166 Jun-08-2019, 04:06 PM
Last Post: SheeppOSU
  Changing Number Format moby 4 194 May-24-2019, 11:04 PM
Last Post: snippsat
  changing { and } in str.format() Skaperen 10 455 May-16-2019, 05:07 AM
Last Post: Skaperen
  Getting error message for indentation Shafla 5 185 May-07-2019, 08:56 PM
Last Post: Yoriz
  Is there a way to automate changing the lines in a .txt like this? ejected 3 237 May-05-2019, 11:50 PM
Last Post: Skaperen
  "Illegal variable name" message shown when trying to compile program thesurya7 2 189 Apr-19-2019, 08:13 AM
Last Post: thesurya7
  Problem to sent message with pyserial and ser.write DJ_Depannage 18 552 Apr-15-2019, 08:45 PM
Last Post: DJ_Depannage

Forum Jump:


Users browsing this thread: 1 Guest(s)