918 questions
0
votes
0
answers
35
views
Python: is there a straightforward way to determine if it is safe to move a line of code outside of a try-except? [duplicate]
Suppose you have some code like this:
def some_func():
try:
func_a()
func_b()
func_c()
except SomeException as e:
print("An exception occurred.")
Is ...
-3
votes
2
answers
90
views
execution of try and exception in output [closed]
I'm having a problem with a program where it runs the exception along with the try command and I don't know what to do since it prints the conversion and the error message.
def main():
print('What ...
2
votes
1
answer
1k
views
Yahoo Finance YFTzMissingError not being recognized in try except
I am trying to write basic code that continues when a valid ticker (stock symbol) is input and restarts if the ticker is invalid. I thought I would try a while True / try / except method. This works ...
1
vote
1
answer
141
views
C++ EXCEPTION_FLT_DIVIDE_BY_ZERO hardware exception not caught
I have three dedicated functions, each containing a __try/_except block, and in which a EXCEPTION_ACCESS_VIOLATION, EXCEPTION_INT_DIVIDE_BY_ZERO, and EXCEPTION_FLT_DIVIDE_BY_ZERO exception should be ...
0
votes
0
answers
46
views
logger crashed when selenium not found element by xpath
So, this code crushed when web driver not found element:
try:
driver.find_element(By.XPATH, "//span[contains(.,'some_text')]").get_attribute('innerHTML')
except Exception as e:
logger....
2
votes
1
answer
51
views
Python3.11 handle HttpException raised alongwith the status code
I see one of the methods in python uses raise_for_status():
def raise_for_status(self):
if 400 <= self.status_code < 500:
http_error_msg = (
...
0
votes
1
answer
89
views
In python, when raising an exception from an except block, is there a way to stop a traceback?
This code:
def abc():
raise ValueError()
def xyz():
try:
raise TypeError()
except TypeError:
abc()
xyz()
creates the following traceback:
Traceback (most recent call ...
-6
votes
3
answers
82
views
Scope Variable inside Python's Try, Except block
At first, i wrote my simple code as below:
while True:
try:
x = int(input("what's x? "))
except ValueError:
print(f"x is not an integer!")
else:
...
3
votes
1
answer
79
views
Print list (or tree) of active TRY blocks
I am debugging some complicated legacy Python3 code and find myself needing to know, at a particular point in the executing code, all the try blocks that are active in the call stack. Is there a way ...
0
votes
2
answers
182
views
Python try/except not stopping errors
My following code was designed to handle exceptions and switch serialport if nothing was found.
try:
serial_port = '/dev/cu.usbserial-10'
except:
try:
serial_port = '/dev/cu.usbserial-...
-1
votes
1
answer
61
views
python try except misuse - what should i use instead? [duplicate]
I'm working with an external API and trying to automatically feed data from it into my own application.
Let's say that the API call i'm making always has the fields 'length' and 'girth' and sometimes ...
2
votes
2
answers
162
views
Python: Is there a way to save a value in the try block and pass it onto the except block?
I want to accomplish the following:
I have a global variable x assigning to int(input('x: ')) in the try block, but I want to pass the value of x in the except block to alert the user that the ...
1
vote
1
answer
233
views
How can I catch exeption of scipy.sparse.linalg.spsolve() (Windows fatal exception: access violation)
I am using scipy.sparse.linalg.spsolve() to solve a set of linear equations in a loop where the equations are opdated iteratively based on the previous solution. Sometimes I end up in a singular ...
1
vote
1
answer
105
views
how to get more info from try/except
I'm having problems with my code in python where basically I make several SSH connection.
I'm always using this format:
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko....
0
votes
1
answer
64
views
merging exceptions in try/except
I'm an experience Perl programmer relatively new to Python.
I'm writing a simple program which uses requests.get(), in a try/except block. pylint complains my bare 'except:' was too bare, so I made it ...