Too Broad of an exception

2023-10-25 Thread rsutton via Python-list

Hi all,
I am fairly new to python (ie < 2 years).  I have a question about 
pylint.  I am running on windows 10/11, python 3.10.11.


Here's what I'm trying to do:
I am using robocopy to to copy a set of files to/from a LAN location and 
my desktop(s).  Here is the partial code:


p = subprocess.run(["robocopy.exe",
STORE_LOCATION, NEWS_LOCATION,
"/NFL", "/NDL", "/NJH", "/NJS", "/NP", "/XF", 
"msgFilterRules.dat",

"xmsgFilterRules.dat"], check=False)

# this is necessary because Windows Robocopy returns
# various return codes for success.
if p.returncode >= 8:
raise Exception(f'Invalid result: {p.returncode}')

It actually runs fine.  But pylint is not having it.  I get:

win_get_put_tb_filters.py:61:12: W0719: Raising too general exception: 
Exception (broad-exception-raised)


But the code I have written does exactly what I want.  If the returncode 
is 7 or less, then I have success.  If the returncode is 8 or above 
there is a failure and I want to see what the returncode is.


Trying to read the python Exception docs is mind bending.  Any help 
would be appreciated.


Richard
--
https://mail.python.org/mailman/listinfo/python-list


Re: Too Broad of an exception

2023-10-25 Thread rsutton via Python-list

On 10/25/2023 11:06 AM, Stefan Ram wrote:

r...@zedat.fu-berlin.de (Stefan Ram) writes:

outer quotation marks) prints some prominent exception types. After
manually removing those that do not seem to apply, I am left with:
"AssertionError",
"ChildProcessError",

...

   "Manually removing" above was meant to be a fast first pass,
   where I only excluded exception types that were obviously
   inappropriate. It is now to be followed by a search for the
   appropriate exception types among those exception types left.



@Rene & @Stefan,
I really appreciate the guidance provided.  By replacing Exception with 
RuntimeError, pylint seems happy!  More specificity, I guess.  I know 
that I could have ignored the pylint exceptions, but I want to use this 
as a learning experience.  I looks like I have a lot of reading to do on 
exception handling. IMO all of the try/except code looks quite clumsy to 
me.  It may be excellent for some tasks but to me, it looks quite 
inelegant.  Like I said, I have a lot to learn.


Thank you both for your guidance.

Richard

--
https://mail.python.org/mailman/listinfo/python-list