Re: [sage-devel] About exceptions

2016-10-13 Thread Jeroen Demeyer
On 2016-10-13 10:56, Jori Mäntysalo wrote: I opened https://trac.sagemath.org/ticket/2169 to make some example. I guess you mean that for example ValueError("%s and %s must be positive integers." % (m, n)) should be as it is, but ValueError("the poset is not ranked") changed to ArithmeticErr

Re: [sage-devel] About exceptions

2016-10-13 Thread Jori Mäntysalo
I opened https://trac.sagemath.org/ticket/2169 to make some example. I guess you mean that for example ValueError("%s and %s must be positive integers." % (m, n)) should be as it is, but ValueError("the poset is not ranked") changed to ArithmeticError. -- Jori Mäntysalo

Re: [sage-devel] About exceptions

2016-10-13 Thread Daniel Krenn
On 2016-10-13 08:11, Jeroen Demeyer wrote: > On 2016-10-12 13:39, Jori Mäntysalo wrote: >> elements = D.topological_sort() > > More bikeshedding: in this case, I would even consider ArithmeticError. > It's not strictly arithmetic, but it does indicate a mathematical issue. > I tend to use

Re: [sage-devel] About exceptions

2016-10-13 Thread Daniel Krenn
On 2016-10-12 16:01, Daniel Krenn wrote: > On 2016-10-12 13:39, Jori Mäntysalo wrote: > There could be a ContainsCycleError which has RuntimeError as a base... As mentioned in another part of this thread: ...ArithmethicError as a base... -- You received this message because you are subscribed t

Re: [sage-devel] About exceptions

2016-10-13 Thread Jori Mäntysalo
On Thu, 13 Oct 2016, Jeroen Demeyer wrote: So we have now a common view that 'type' in TypeError should (mostly?) refer to types in wrong class, wrong category etc For Sage, I would certainly add "wrong parent" to this. True. And there might be some, eh, exceptions to this rule. But mostly

Re: [sage-devel] About exceptions

2016-10-12 Thread Jeroen Demeyer
On 2016-10-12 13:39, Jori Mäntysalo wrote: elements = D.topological_sort() More bikeshedding: in this case, I would even consider ArithmeticError. It's not strictly arithmetic, but it does indicate a mathematical issue. I tend to use ArithmeticError for mathematical errors (something

Re: [sage-devel] About exceptions

2016-10-12 Thread Jeroen Demeyer
On 2016-10-12 18:56, Jori Mäntysalo wrote: So we have now a common view that 'type' in TypeError should (mostly?) refer to types in wrong class, wrong category etc For Sage, I would certainly add "wrong parent" to this. Python also uses TypeError to indicate a function which is called with th

Re: [sage-devel] About exceptions

2016-10-12 Thread Volker Braun
On Wednesday, October 12, 2016 at 4:01:51 PM UTC+2, Daniel Krenn wrote: > > There could be a ContainsCycleError which has RuntimeError as a base... > +1 -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop rec

Re: [sage-devel] About exceptions

2016-10-12 Thread Jori Mäntysalo
First, to answer my own question: at least for Python 3 see https://docs.python.org/3/library/exceptions.html Only exceptions not catch by "except Exception:" are SystemExit, KeyboardInterrupt and GeneratorExit. Hence only real difference between "except Exception:" and "except:" is that lat

Re: [sage-devel] About exceptions

2016-10-12 Thread Daniel Krenn
On 2016-10-12 16:29, Travis Scrimshaw wrote: > > > On Wednesday, October 12, 2016 at 9:01:51 AM UTC-5, Daniel Krenn wrote: > > On 2016-10-12 13:39, Jori Mäntysalo wrote: > > More about this: In posets.py there is > > > > try: > > elements = D.topological_sort() >

Re: [sage-devel] About exceptions

2016-10-12 Thread Travis Scrimshaw
On Wednesday, October 12, 2016 at 9:01:51 AM UTC-5, Daniel Krenn wrote: > > On 2016-10-12 13:39, Jori Mäntysalo wrote: > > More about this: In posets.py there is > > > > try: > > elements = D.topological_sort() > > except Exception: > > raise ValueError("Hasse diagra

Re: [sage-devel] About exceptions

2016-10-12 Thread Daniel Krenn
On 2016-10-12 13:39, Jori Mäntysalo wrote: > More about this: In posets.py there is > > try: > elements = D.topological_sort() > except Exception: > raise ValueError("Hasse diagram contains cycles.") > > and that should be "except TypeError", as that is what > .topological

Re: [sage-devel] About exceptions

2016-10-12 Thread 'Martin R' via sage-devel
wouldn't it make sense to catch "everything reasonable"? I could imagine that for some reason at some point it is decided that the method you call raises a slightly different error. Would that be bad? Martin -- You received this message because you are subscribed to the Google Groups "sage

Re: [sage-devel] About exceptions

2016-10-12 Thread Jori Mäntysalo
More about this: In posets.py there is try: elements = D.topological_sort() except Exception: raise ValueError("Hasse diagram contains cycles.") and that should be "except TypeError", as that is what .topological_sort() raises from DiGraph that is not acyclic. But shou

Re: [sage-devel] About exceptions

2016-10-12 Thread Jori Mäntysalo
On Wed, 12 Oct 2016, Jeroen Demeyer wrote: What you expect. A MemoryError will be raised, which is caught by the "except Exception". OK. What are exceptions that "except Exception:" does not catch, but "except:" will catch? So I agree that code like the above is bad (but not nearly as bad a

Re: [sage-devel] About exceptions

2016-10-12 Thread Jeroen Demeyer
On 2016-10-12 12:47, Jori Mäntysalo wrote: After #21687 there are 341 lines in 172 files with except Exception: What can happen in, say has_vertex() in generic graphs, when it has the code try: hash(vertex) except Exception: return False return self._backend.ha