Re: Exception

2019-09-24 Thread ast
Le 24/09/2019 à 15:51, אורי a écrit : https://stackoverflow.com/a/24752607/1412564 thank you for link. it's clear now -- https://mail.python.org/mailman/listinfo/python-list

Re: Exception

2019-09-24 Thread אורי
https://stackoverflow.com/a/24752607/1412564 אורי u...@speedy.net On Tue, Sep 24, 2019 at 4:07 PM ast wrote: > Hi > > It is not clear to me why the following code > generates 2 exceptions, ZeroDivisionError and > ArithmeticError. Since ZeroDivisionError is > catched, it shoud not bubble out. >

RE: Exception

2019-09-24 Thread David Raymond
I believe the idea is that previously, if you were handling an exception, and your handling code caused its own exception, then you would get no info about the original exception. So all useful information about the original problem would get lost because of an oopsie in the handling code. So it

Re: exception should not stop program.

2017-10-07 Thread MRAB
On 2017-10-07 17:38, Prabu T.S. wrote: I would like to continue to second function invocation "checkServiceStatus('AdobeARMservice')" even if the first checkServiceStatus('Tomcat9') has any exception.Please advice.Second function invocation not getting executed if any exception occurs in

Re: exception should not stop program.

2017-10-07 Thread Grant Edwards
On 2017-10-07, Jorge Gimeno wrote: > Catching all exceptions in a try-except block is almost always a bad > idea. Catching it and ignoring it as the OP was doing (or assuming it's some particular exception) certainly is. If you know (or suspect) that stderr isn't going anywhere that it will be

Re: exception should not stop program.

2017-10-07 Thread Jorge Gimeno
Catching all exceptions in a try-except block is almost always a bad idea. You can't tell the difference between an exception that you are looking to handle and an exception that should cause your program to crash and burn (because something is wrong). It's best to catch a specific exception. What

Re: exception should not stop program.

2017-10-07 Thread Prabu T.S.
On Saturday, October 7, 2017 at 12:38:11 PM UTC-4, Prabu T.S. wrote: > I would like to continue to second function invocation > "checkServiceStatus('AdobeARMservice')" even if the first >checkServiceStatus('Tomcat9') has any exception.Please advice.Second > function invocation not getting e

Re: Exception from pyd methods

2016-03-19 Thread dieter
Palpandi writes: > I am using methods from pyd files. At some cases, it is throwing some error > messages in the console. > > When I use try.. except.. I am getting only the exception name. > Not able to catch the entire error message. > > How do I get the the entire error message printed in the

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-19 Thread shaunak . bangale
On Monday, February 8, 2016 at 1:05:08 AM UTC-7, shaunak...@gmail.com wrote: > On Sunday, February 7, 2016 at 1:23:32 AM UTC-7, dieter wrote: > > Shaunak Bangale writes: > > > ... > > > while (count > 0): > > > try : > > > # read line from file: > > > print(file.readline()) > >

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-08 Thread shaunak . bangale
On Sunday, February 7, 2016 at 1:23:32 AM UTC-7, dieter wrote: > Shaunak Bangale writes: > > ... > > while (count > 0): > > try : > > # read line from file: > > print(file.readline()) > > # parse > > parse_json(file.readline()) > > count = count - 1 > >

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-07 Thread dieter
Shaunak Bangale writes: > ... > while (count > 0): > try : > # read line from file: > print(file.readline()) > # parse > parse_json(file.readline()) > count = count - 1 > except socket.error as e: > print('Connection fail', e) > print

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-06 Thread Shaunak Bangale
I do have the initiation command defined. Just that I am not allowed to make the username, pwd public. I am absolutely sure I am running the same code. Now opened the same file with Python 3.5 shell and I get following error: from _ssl import RAND_status, RAND_egd, RAND_add ImportError: cannot

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-06 Thread Shaunak Bangale
Hi Martin, Answering your questions below: On Fri, Feb 5, 2016 at 1:50 PM, Shaunak Bangale wrote: > Hi Martin, > > Thanks for the detailed reply. I edited, saved and opened the file again. > Still I am getting exactly the same error. > > Putting bigger chunk of code and the error again: > > >

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-06 Thread Shaunak Bangale
Hi Martin, Thanks for the detailed reply. I edited, saved and opened the file again. Still I am getting exactly the same error. Putting bigger chunk of code and the error again: # create socket s = socket.socket(socket.AF_INET) #create a SSL context with the recommended security settings for c

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Chris Angelico
On Sat, Feb 6, 2016 at 9:35 AM, wrote: > On Friday, February 5, 2016 at 12:58:37 PM UTC-7, shaunak...@gmail.com wrote: >> I am running this python script on R-studio. I have Python 3.5 installed on >> my system. >> >> count = 10 >> while (count > 0): >> try : >> # read line from file

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread shaunak . bangale
On Friday, February 5, 2016 at 12:58:37 PM UTC-7, shaunak...@gmail.com wrote: > I am running this python script on R-studio. I have Python 3.5 installed on > my system. > > count = 10 > while (count > 0): > try : > # read line from file: > print(file.readline()) > # pa

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread shaunak . bangale
On Friday, February 5, 2016 at 12:58:37 PM UTC-7, shaunak...@gmail.com wrote: > I am running this python script on R-studio. I have Python 3.5 installed on > my system. > > count = 10 > while (count > 0): > try : > # read line from file: > print(file.readline()) > # pa

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Chris Angelico
On Sat, Feb 6, 2016 at 8:08 AM, Bernardo Sulzbach wrote: > On 02/05/2016 07:01 PM, Chris Angelico wrote: >> >> On Sat, Feb 6, 2016 at 6:58 AM, wrote: >>> >>> I am running this python script on R-studio. I have Python 3.5 installed >>> on my system. >>> >> >> Let's just try a quick smoke test. Ru

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Bernardo Sulzbach
On 02/05/2016 07:26 PM, shaunak.bang...@gmail.com wrote: from _ssl import RAND_status, RAND_egd, RAND_add ImportError: cannot import name 'RAND_egd' I believe I've already seen this issue myself. It has to do with LibreSSL not having RAND_egd for some reason I can't recall. This seems

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread shaunak . bangale
On Friday, February 5, 2016 at 2:09:11 PM UTC-7, Bernardo Sulzbach wrote: > On 02/05/2016 07:01 PM, Chris Angelico wrote: > > On Sat, Feb 6, 2016 at 6:58 AM, wrote: > >> I am running this python script on R-studio. I have Python 3.5 installed > >> on my system. > >> > > > > Let's just try a quic

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Bernardo Sulzbach
On 02/05/2016 07:01 PM, Chris Angelico wrote: On Sat, Feb 6, 2016 at 6:58 AM, wrote: I am running this python script on R-studio. I have Python 3.5 installed on my system. Let's just try a quick smoke test. Run this script: import sys print(sys.version) input("Press Enter to exit...") Th

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Martin A. Brown
Hi there, >Thanks for the detailed reply. I edited, saved and opened the file >again. Still I am getting exactly the same error. > >Putting bigger chunk of code and the error again: [snipped; thanks for the larger chunk] >Error: >except socket.error as e: > ^ >SyntaxErr

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Chris Angelico
On Sat, Feb 6, 2016 at 6:58 AM, wrote: > I am running this python script on R-studio. I have Python 3.5 installed on > my system. > Let's just try a quick smoke test. Run this script: import sys print(sys.version) input("Press Enter to exit...") That'll tell you a few things about how your sy

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Martin A. Brown
Hi there Shaunak, I saw your few replies to my (and Nathan's) quick identification of syntax error. More comments follow, here. >I am running this python script on R-studio. I have Python 3.5 installed on my >system. > >count = 10 >while (count > 0): >try : ># read line from file:

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread shaunak . bangale
On Friday, February 5, 2016 at 1:09:35 PM UTC-7, Martin A. Brown wrote: > >except socket.error as e > > >line 53 except socket.error as e ^ SyntaxError: invalid syntax > > > >I tried changing socket.error to ConnectionRefusedError. and still > >got the same error. > > >Please tell me if the

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread shaunak . bangale
On Friday, February 5, 2016 at 1:11:19 PM UTC-7, shaunak...@gmail.com wrote: > On Friday, February 5, 2016 at 1:08:11 PM UTC-7, Nathan Hilterbrand wrote: > > On Feb 5, 2016 15:01, wrote: > > > > > > I am running this python script on R-studio. I have Python 3.5 installed > > on my system. > > > >

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread shaunak . bangale
On Friday, February 5, 2016 at 1:08:11 PM UTC-7, Nathan Hilterbrand wrote: > On Feb 5, 2016 15:01, wrote: > > > > I am running this python script on R-studio. I have Python 3.5 installed > on my system. > > > > count = 10 > > while (count > 0): > > try : > > # read line from file: > >

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Martin A. Brown
>except socket.error as e >line 53 except socket.error as e ^ SyntaxError: invalid syntax > >I tried changing socket.error to ConnectionRefusedError. and still >got the same error. >Please tell me if the problem is with Rstudio, Python version or >the syntax. Syntax. Your code has, unfor

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Nathan Hilterbrand
On Feb 5, 2016 15:01, wrote: > > I am running this python script on R-studio. I have Python 3.5 installed on my system. > > count = 10 > while (count > 0): > try : > # read line from file: > print(file.readline()) > # parse > parse_json(file.readline()) >

Re: Exception AttributeError: "'NoneType' object has no attribute 'population'"

2015-08-24 Thread MRAB
On 2015-08-24 06:49, 344276105 wrote: Hi all, I am a python learner. I encountered a problem when i was testing the following code. What is strange is that if I replace the object name with zhang, the program would be ok. And if I replace the Person.population with self.__class__.population, it w

Re: Exception in thread Thread-4:

2015-05-05 Thread david jhon
Hi Chris, Thanks a lot for such a comprehensive reply, I got it fixed now. Thanks again :) On Tue, May 5, 2015 at 2:52 PM, Chris Angelico wrote: > On Tue, May 5, 2015 at 7:23 PM, david jhon wrote: > > from threading import Timer, Lock > > > > class miTestClass(EventMixin): > > def __init__

Re: Exception in thread Thread-4:

2015-05-05 Thread Chris Angelico
On Tue, May 5, 2015 at 7:23 PM, david jhon wrote: > from threading import Timer, Lock > > class miTestClass(EventMixin): > def __init__(self, t, r, bw): > self.statMonitorLock = Lock() #to lock the multi access threads > self.statMonitorLock.acquire() > statMonitorTi

Re: Exception Handling

2015-04-10 Thread dieter
Palpandi writes: > Thanks for your responses. And I have one more question. > This is the situation. A python application which reads data from one .xml > file and generates some other file. Here what kind of exceptions occur? Ideally, you would not get any exceptions. In the not ideal case, y

Re: Exception Handling

2015-04-09 Thread Steven D'Aprano
On Thu, 9 Apr 2015 07:31 pm, Palpandi wrote: > Hi all, > > Is there any way to roll back or undo changes which are all done before > exception occurs. Not automatically. You have to program it yourself. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Exception Handling

2015-04-09 Thread Chris Angelico
On Thu, Apr 9, 2015 at 7:31 PM, Palpandi wrote: > Hi all, > > Is there any way to roll back or undo changes which are all done before > exception occurs. In Python itself? Not directly; there are no facilities for undoing Python code. But if you're serious about integrity, you probably want to b

RE: Exception problem with module

2014-05-19 Thread Joseph L. Casale
>> Well I am not sure what advantage this has for the user, not my code as >> I don't advocate the import to begin with it, its fine spelled as it was >> from where it was... > > The advantage for the user is: /snip Hey Steven, Sorry for the late reply (travelling). My comment wasn't clear, I wa

Re: Exception problem with module

2014-05-14 Thread Chris Angelico
On Wed, May 14, 2014 at 11:08 PM, Steven D'Aprano wrote: > One should code as if the next person who reads your program is an easily > upset psychotic axe-murderer who knows where you live. You wouldn't > condone writing y = x.__add__(1) instead of y = x + 1, you shouldn't > condone writing module

Re: Exception problem with module

2014-05-14 Thread Steven D'Aprano
On Wed, 14 May 2014 09:21:50 +, Joseph L. Casale wrote: >> I see that you've solved your immediate problem, but you shouldn't call >> __setattr__ directly. That should actually be written >> >> setattr(bar, 'a_new_name', MyError) >> >> But really, since bar is (apparently) a module, and it

RE: Exception problem with module

2014-05-14 Thread Joseph L. Casale
> I see that you've solved your immediate problem, but you shouldn't call > __setattr__ directly. That should actually be written > > setattr(bar, 'a_new_name', MyError) > > But really, since bar is (apparently) a module, and it is *bar itself* > setting the attribute, the better way is > > a

Re: Exception problem with module

2014-05-13 Thread Steven D'Aprano
On Tue, 13 May 2014 16:59:46 +, Joseph L. Casale wrote: > I am working with a module that I am seeing some odd behavior. > > A module.foo builds a custom exception, module.foo.MyError, its done > right afaict. > > Another module, module.bar imports this and calls > bar.__setattr__('a_new_nam

RE: Exception problem with module

2014-05-13 Thread Joseph L. Casale
> Best would be to print out what's in a_new_name to see if it really is > what you think it is. If you think it is what you think it is, have a > look at its __mro__ (method resolution order, it's an attribute of > every class), to see what it's really inheriting. That should show you > what's hap

Re: Exception problem with module

2014-05-13 Thread Chris Angelico
On Wed, May 14, 2014 at 2:59 AM, Joseph L. Casale wrote: > During handling of the above exception, another exception occurred: > > File "C:/dir/test.py", line 12, in > except a_new_name as exc: > TypeError: catching classes that do not inherit from BaseException is not > allowed Best woul

Re: Exception Handling Practices / Patterns

2013-08-24 Thread frank . ruiz
Hi Steven, Yea this is great. Thanks for the feedback. On Saturday, August 24, 2013 3:27:45 AM UTC-7, Steven D'Aprano wrote: > On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: > > > > [...] > > > * Seems like exception handing within Classes is largely avoided and is > > > typically only use

Re: Exception Handling Practices / Patterns

2013-08-24 Thread frank . ruiz
Appreciate the feedback. I was hoping to get as much perspective as possible. On Saturday, August 24, 2013 12:18:59 AM UTC-7, Dave Angel wrote: > snarf wrote: > > > > > Greetings, > > > > > > As I tread through my journey of OO I am trying to determine if there is a > > good approach for ex

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
On Sat, 24 Aug 2013 15:57:55 -0400, Terry Reedy wrote: >> # Worst >> except: >> >> Don't use the last one, except maybe in the interactive interpreter, > > Stick with never. "except:" means the same thing as "except > BaseException:", except that the latter indicates a deliberate choice > rather

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Terry Reedy
On 8/24/2013 6:27 AM, Steven D'Aprano wrote: On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: [...] * Seems like exception handing within Classes is largely avoided and is typically only used when calling external libraries. There is certainly no rule "avoid exceptions inside classes". Method

Re: Exception Handling Practices / Patterns

2013-08-24 Thread MRAB
On 24/08/2013 11:27, Steven D'Aprano wrote: On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: [snip] * Using Exception is typically a bad. More specific the better. Yes, you should always try to catch the specific exceptions you care about: # Best except ValueError, OverflowError, ZeroDivisi

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: [...] > * Seems like exception handing within Classes is largely avoided and is > typically only used when calling external libraries. There is certainly no rule "avoid exceptions inside classes". Methods often raise exceptions to signal an error

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Dave Angel
snarf wrote: > Greetings, > > As I tread through my journey of OO I am trying to determine if there is a > good approach for exception handling within classes. > > From my readings and gatherings - it seems I have found a common theme, but I > am trying to solicit from the experts. > > Here is w

Re: Exception in thread QueueFeederThread (most likely raised during interpreter shutdown)

2013-02-21 Thread Ziliang Chen
On Thursday, February 21, 2013 2:20:41 AM UTC+8, MRAB wrote: > On 2013-02-20 08:26, Ziliang Chen wrote: > Hi Guys, > I am using the > multiprocessing module. The following code snippet occasionally throws the > "Exception in thread QueueFeederThread (most likely raised during interpreter > shutd

Re: Exception in thread QueueFeederThread (most likely raised during interpreter shutdown)

2013-02-20 Thread MRAB
On 2013-02-20 08:26, Ziliang Chen wrote: Hi Guys, I am using the multiprocessing module. The following code snippet occasionally throws the "Exception in thread QueueFeederThread (most likely raised during interpreter shutdown)" exception. I searched google for the cause, someone says there ar

Re: Exception running GNU module "op25_grc.py" : AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'

2013-02-16 Thread matt . doolittle33
> > I know nothing about this gnuradio thingie, and you didn't supply a > > website url. I was wondering if the module is even intended to be run > > standalone, but I suppose the if __name__ == "__main__" thing is a clue > > that it's supposed to. > > > > I found the mixture of trace li

Re: Exception running GNU module "op25_grc.py" : AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'

2013-02-15 Thread Dave Angel
On 02/15/2013 02:00 PM, matt.doolittl...@gmail.com wrote: I am using using ubuntu 12.10 i am trying to run a python block, namely OP25, in GNU Radio Companion v3.6.3-35-g4435082f, which uses python version 2.7.3 for some reason although python3.2 is in the lib folder. I run the following trace

Re: "Exception ... in ignored" Messages

2013-02-15 Thread Peter Otten
Ami Tavory wrote: > From: Peter Otten <__pete...@web.de> > To: python-list@python.org > Cc: > Date: Thu, 14 Feb 2013 09:00:58 +0100 > Subject: Re: "Exception ... in ignored" Messages How did the subject get into the message body? > Ami Tavory wrote: > &g

Re: "Exception ... in ignored" Messages

2013-02-14 Thread Peter Otten
Ami Tavory wrote: > Hi, > > Running the unit tests for some generator code, prints, as a side > effect, > numerous messages of the form: > > ... > Exception NameError: "global name 'l' is not defined" in _dagpype_internal_fn_act at 0x9d4c500> ignored > Exception AttributeError: "'NoneType

Re: Exception Messages

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 09:00:15 -0700, Wanderer wrote: > How do you get Exceptions to print messages? I have an exception defined > like this > > class PvCamError(Exception): > def __init__(self, msg): > self.msg = msg Please don't invent yet another interface for exception messages. E

Re: Exception Messages

2012-10-15 Thread Terry Reedy
On 10/15/2012 12:22 PM, John Gordon wrote: In MRAB writes: Why wasn't the message printed out? You didn't add a __str__ method: class PvCamError(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return self.msg Wouldn't PvCamError i

Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:34:24 PM UTC-4, MRAB wrote: > On 2012-10-15 18:18, Wanderer wrote: > > > On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: > > > > > >> > > >> Yes, but you've put the message in msg, and Exception doesn't have that > > >> > > >> attribute. > > >> > > >

Re: Exception Messages

2012-10-15 Thread MRAB
On 2012-10-15 18:18, Wanderer wrote: On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: Yes, but you've put the message in msg, and Exception doesn't have that attribute. That's weird. I got this Exception class definition idea from this post by Guido van Rostrum, Where he gives t

Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:18:52 PM UTC-4, Wanderer wrote: > On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: > > > > > > > > Yes, but you've put the message in msg, and Exception doesn't have that > > > > > > attribute. > > > > > > > That's weird. I got this Exception cla

Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote: > > Yes, but you've put the message in msg, and Exception doesn't have that > > attribute. > That's weird. I got this Exception class definition idea from this post by Guido van Rostrum, Where he gives this main function to look like

Re: Exception Messages

2012-10-15 Thread Dave Angel
On 10/15/2012 12:34 PM, MRAB wrote: > On 2012-10-15 17:22, John Gordon wrote: >> In MRAB >> writes: >> >>> > Why wasn't the message printed out? >>> >>> You didn't add a __str__ method: >> >>> class PvCamError(Exception): >>> def __init__(self, msg): >>> self.msg = msg >>> def

Re: Exception Messages

2012-10-15 Thread MRAB
On 2012-10-15 17:22, John Gordon wrote: In MRAB writes: > Why wasn't the message printed out? You didn't add a __str__ method: class PvCamError(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return self.msg Wouldn't PvCamError inherit

Re: Exception Messages

2012-10-15 Thread John Gordon
In MRAB writes: > > Why wasn't the message printed out? > > You didn't add a __str__ method: > class PvCamError(Exception): > def __init__(self, msg): > self.msg = msg > def __str__(self): > return self.msg Wouldn't PvCamError inherit __str__() from Exception? --

Re: Exception Messages

2012-10-15 Thread MRAB
On 2012-10-15 17:00, Wanderer wrote: How do you get Exceptions to print messages? I have an exception defined like this class PvCamError(Exception): def __init__(self, msg): self.msg = msg But when the error is raised I get this: Traceback (most recent call last): File "C:\P

Re: exception problem

2012-06-28 Thread Ethan Furman
Charles Hixson wrote: On 06/25/2012 12:48 AM, Steven D'Aprano wrote: "Catch any exception" is almost certainly the wrong thing to do, almost always. This time it was the right thing No, it wasn't. If you hadn't caught it, Python would have printed it out for you, along with the full tra

Re: exception problem

2012-06-27 Thread Steven D'Aprano
On Wed, 27 Jun 2012 17:13:00 -0700, Charles Hixson wrote: > On 06/25/2012 12:48 AM, Steven D'Aprano wrote: >> On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote: >> >> >>> But what I wanted was to catch any exception. >>> >> Be careful of what you ask for, since you might get it. >> >>

Re: exception problem

2012-06-27 Thread alex23
On Jun 28, 10:13 am, Charles Hixson wrote: > On 06/25/2012 12:48 AM, Steven D'Aprano wrote: > > "Catch any exception" is almost certainly the wrong thing to do, almost > > always. > This time it was the right thing, as I suspected that *SOME* exception > was being thrown, but had no idea what one

Re: exception problem

2012-06-27 Thread Charles Hixson
On 06/25/2012 12:48 AM, Steven D'Aprano wrote: On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote: But what I wanted was to catch any exception. Be careful of what you ask for, since you might get it. "Catch any exception" is almost certainly the wrong thing to do, almost alwa

Re: exception problem

2012-06-26 Thread MRAB
On 26/06/2012 22:36, Chris Angelico wrote: (You posted privately to me again; I hope you don't mind my responding on-list as this appears to have been merely oversight.) On Wed, Jun 27, 2012 at 5:25 AM, Charles Hixson wrote: Only thing is, this whole mess started when I was trying to trace dow

Re: exception problem

2012-06-26 Thread Chris Angelico
(You posted privately to me again; I hope you don't mind my responding on-list as this appears to have been merely oversight.) On Wed, Jun 27, 2012 at 5:25 AM, Charles Hixson wrote: > Only thing is, this whole mess started when I was trying to trace down and > expected error.  (Which turned out t

Re: exception problem

2012-06-25 Thread Chris Angelico
On Tue, Jun 26, 2012 at 1:14 AM, Charles Hixson wrote: > I read that that would happen, but "  print (sys.exc_info()[:2]) " didn't > even yield a blank line.  It must have executed, because the print statement > on the line before it executed, and there wasn't a loop or a jump (and also > executio

Re: exception problem

2012-06-25 Thread Charles Hixson
On 06/24/2012 11:23 PM, Andrew Berg wrote: On 6/25/2012 12:27 AM, Charles Hixson wrote: The documentation section covering the except statement could stand to be a *LOT* clearer. I read the sections on the except statement and exception handlers several times and couldn't figure out was th

Re: exception problem

2012-06-25 Thread Chris Angelico
On Mon, Jun 25, 2012 at 5:49 PM, Steven D'Aprano wrote: > On Mon, 25 Jun 2012 09:51:15 +1000, Chris Angelico wrote: > >> Mind you, I think every programmer should spend some time debugging >> blind. > > You're a cruel, cruel man. > > I suppose next you're going to say that every programmer should

Re: exception problem

2012-06-25 Thread Steven D'Aprano
On Mon, 25 Jun 2012 09:51:15 +1000, Chris Angelico wrote: > Mind you, I think every programmer should spend some time debugging > blind. You're a cruel, cruel man. I suppose next you're going to say that every programmer should spend some time programming using Notepad as their only editor.

Re: exception problem

2012-06-25 Thread Steven D'Aprano
On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote: > But what I wanted was to catch any exception. Be careful of what you ask for, since you might get it. "Catch any exception" is almost certainly the wrong thing to do, almost always. The one good reason I've seen for a bare except is to

Re: exception problem

2012-06-25 Thread Steven D'Aprano
On Sun, 24 Jun 2012 18:45:45 -0400, Dave Angel wrote: > Bare exceptions are the bane of > programming; Using it is like trying to learn to drive while > blindfolded. +1 QOTW I really wish bare exceptions were removed from Python 3. There's no point to try...except any longer, and it's just an

Re: exception problem

2012-06-24 Thread Andrew Berg
On 6/25/2012 12:27 AM, Charles Hixson wrote: > The documentation section covering the except statement could stand to > be a *LOT* clearer. I read the sections on the except statement and > exception handlers several times and couldn't figure out was the "as" > argument of the except statement

RE: exception problem

2012-06-24 Thread Shambhu Rajak
If you are not sure about the Exception, You can adopt a generic way of handling exception. try: except Exception,e: print str(e) -Shambhu -Original Message- From: MRAB [mailto:pyt...@mrabarnett.plus.com] Sent: 25/06/2012 4:14 AM To: python-list@python.org Subject: Re

Re: exception problem

2012-06-24 Thread Charles Hixson
On 06/24/2012 03:43 PM, Charles Hixson wrote: On 06/24/2012 03:36 PM, Chris Angelico wrote: On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson wrote: The code: finally: print ("at finally") print ("chunks =") produces this result: path 3... C

Re: exception problem

2012-06-24 Thread Dave Angel
On 06/24/2012 07:16 PM, Charles Hixson wrote: > On 06/24/2012 03:43 PM, MRAB wrote: >> On 24/06/2012 23:26, Charles Hixson wrote: >>> >>> >>> >> Don't use a bare "except"; it'll catch _any__exception. Catch only what >> you expect. >> >> For all I know, it could be that the name "l" doesn't exist.

Re: exception problem

2012-06-24 Thread Chris Angelico
On Mon, Jun 25, 2012 at 9:16 AM, Charles Hixson wrote: > But what I wanted was to catch any exception.  A problem was happening and I > had no clue as to what it was.  (It turned out to be "self is not defined". >  A silly mistake, but a real one.) > > The odd thing was that if I ran it without th

Re: exception problem

2012-06-24 Thread Charles Hixson
On 06/24/2012 03:43 PM, MRAB wrote: On 24/06/2012 23:26, Charles Hixson wrote: The code: print("pre-chunkLine") chunks=[] try: chunks=self.chunkLine (l) except:

Re: exception problem

2012-06-24 Thread MRAB
On 24/06/2012 23:36, Chris Angelico wrote: On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson wrote: The code: finally: print ("at finally") print ("chunks =") produces this result: path 3... Can you state more clearly the problem, please? I'm se

Re: exception problem

2012-06-24 Thread Dave Angel
On 06/24/2012 06:30 PM, Charles Hixson wrote: > Sorry, I left out: > er$ python3 --version > Python 3.2.3rc1 > > On 06/24/2012 03:26 PM, Charles Hixson wrote: >> The code: >> print("pre-chunkLine") >> chunks=[] >> try: >>

Re: exception problem

2012-06-24 Thread MRAB
On 24/06/2012 23:26, Charles Hixson wrote: The code: print("pre-chunkLine") chunks=[] try: chunks=self.chunkLine (l) except: print("caught exception")

Re: exception problem

2012-06-24 Thread Chris Angelico
On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson wrote: > The code: >                finally: >                    print ("at finally") >                print ("chunks =") > produces this result: > path  3... Can you state more clearly the problem, please? I'm seeing output that can't have come fr

Re: exception problem

2012-06-24 Thread Charles Hixson
Sorry, I left out: er$ python3 --version Python 3.2.3rc1 On 06/24/2012 03:26 PM, Charles Hixson wrote: The code: print("pre-chunkLine") chunks=[] try: chunks=self.chunkLine (l) except:

Re: Exception Handling (C - extending python)

2011-10-25 Thread Stefan Behnel
Ulrich Eckhardt, 25.10.2011 08:49: Am 23.10.2011 14:41, schrieb Stefan Behnel: That's just fine. If you are interested in the inner mechanics of the CPython runtime, reading the source is a very good way to start getting involved with the project. However, many extension module authors don't ca

Re: Exception Handling (C - extending python)

2011-10-25 Thread Ulrich Eckhardt
Am 23.10.2011 14:41, schrieb Stefan Behnel: That's just fine. If you are interested in the inner mechanics of the CPython runtime, reading the source is a very good way to start getting involved with the project. However, many extension module authors don't care about these inner mechanics and j

Re: Exception Handling (C - extending python)

2011-10-23 Thread Lee
For a moment, back to the basics... I am using the example provided by docs at 2.1.2 "Providing finer control...". Using say: mynoddy = noddy2.Noddy() mynoddy.first = "a" mynoddy.last = 0 the last line causes an ugly crash (on python 2.6.5 on winxp). No way to catch the exception. As I understa

Re: Exception Handling (C - extending python)

2011-10-23 Thread Stefan Behnel
Hi, note that I reformatted your posting to get the replies back into order. Lee, 23.10.2011 13:32: On Oct 23, 10:06 pm, Stefan Behnel wrote: Lee, 23.10.2011 06:09: Where does PyExc_TypeError (and alike) points to? I can see its declaration - PyAPI_DATA(PyObject *) PyExc_TypeError; - in pyerr

Re: Exception Handling (C - extending python)

2011-10-23 Thread Christian Heimes
Am 23.10.2011 06:09, schrieb Lee: > Hi all, > > Where does PyExc_TypeError (and alike) points to? I can see its > declaration - PyAPI_DATA(PyObject *) PyExc_TypeError; - in pyerrors.h > but I cannot figure out what it is its value, where it is > initialized. It's initialized in Objects/exceptions

Re: Exception Handling (C - extending python)

2011-10-23 Thread Lee
Thanks Stefan, I am just interested to understand the mechanism inside python. If it points to an object that means I can defered it (through ob_type). >From there, how a function like PyErr_SetString knows what exception is? Where its value is kept? Lee On Oct 23, 10:06 pm, Stefan Behnel wro

Re: Exception Handling (C - extending python)

2011-10-23 Thread Stefan Behnel
Lee, 23.10.2011 06:09: Where does PyExc_TypeError (and alike) points to? I can see its declaration - PyAPI_DATA(PyObject *) PyExc_TypeError; - in pyerrors.h but I cannot figure out what it is its value, where it is initialized. It gets initialised inside of the interpreter core and then points

Re: Exception handling in Python 3.x

2010-12-13 Thread Arnaud Delobelle
Ethan Furman writes: > Ethan Furman wrote: >> Arnaud Delobelle wrote: >>> >>> I missed the start of this discussion but there are two simpler ways: >>> >>> def func(iterable): >>> for x in iterable: >>> print(x) >>> return >>> raise ValueError("... empty iterable") >> >> >

Re: Exception handling in Python 3.x

2010-12-13 Thread Ethan Furman
Ethan Furman wrote: Arnaud Delobelle wrote: I missed the start of this discussion but there are two simpler ways: def func(iterable): for x in iterable: print(x) return raise ValueError("... empty iterable") For the immediate case this is a cool solution. Drat --

Re: Exception handling in Python 3.x

2010-12-13 Thread Ethan Furman
Ethan Furman wrote: Please don't top-post. Rob Richardson wrote: -Original Message- I missed the start of this discussion but there are two simpler ways: def func(iterable): for x in iterable: print(x) return raise ValueError("... empty iterable") Or using 3

Re: Exception handling in Python 3.x

2010-12-13 Thread Ethan Furman
Arnaud Delobelle wrote: I missed the start of this discussion but there are two simpler ways: def func(iterable): for x in iterable: print(x) return raise ValueError("... empty iterable") For the immediate case this is a cool solution. Unfortunately, it doesn't fix t

Re: Exception handling in Python 3.x

2010-12-13 Thread Arnaud Delobelle
"Rob Richardson" writes: You shouldn't top-post! > Arnaud, > > Wouldn't your first suggestion exit after the first element in iterable? Yes, after printing that element, which is what the code I quoted did. > And would your second suggestion throw an exception after normal > processing of all

  1   2   3   4   5   >