ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 07 Feb 2015 22:58:28 +0100any way to turn off error msg when I catch the errors?https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/trying to check whether a numerical expression is NaN or not.
My expression is log(arcsin(e)). If I apply N() on the expression it goes into infinite loop. I try to catch the runtime error. Everything seems to work in the following code except the error message displayed. I do not want that message in output. Any way to turn the error message off.
sage: def number(expr):
....: try:
....: n = N(expr)
....: except (RuntimeError):
....: n = N(NaN)
....: return n
....:
sage: expr=log(arcsin(e))
sage: a=number(expr)
Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in <type 'exceptions.RuntimeError'> ignored
# I do not want the above error message in output
sage: a
NaN
sage: a.is_NaN()
True
Fri, 11 Feb 2011 13:19:00 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/Answer by niles for <p>trying to check whether a numerical expression is NaN or not.
My expression is log(arcsin(e)). If I apply N() on the expression it goes into infinite loop. I try to catch the runtime error. Everything seems to work in the following code except the error message displayed. I do not want that message in output. Any way to turn the error message off. </p>
<pre><code>sage: def number(expr):
....: try:
....: n = N(expr)
....: except (RuntimeError):
....: n = N(NaN)
....: return n
....:
sage: expr=log(arcsin(e))
sage: a=number(expr)
Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in <type 'exceptions.RuntimeError'> ignored
# I do not want the above error message in output
sage: a
NaN
sage: a.is_NaN()
True
</code></pre>
https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?answer=12093#post-id-12093This certainly is weird. I think you have an indentation problem in your post, but that doesn't seem to be the problem.
The following is slightly simpler, but also prints the error message for me. (It also prints the error message when I use `except RuntimeError`)
def number(expr):
try:
n = N(expr)
except:
n = 0
return n
Note, by contrast, that the following works without problem (no error message printed):
def divide(n):
try:
r = 1/n
except ZeroDivisionError:
r = Infinity
return r
So it seems this is a bug with the recursion depth RuntimeError . . .
---
UPDATE: Based on the discussion, I've filed a ticked for this: [#10774](http://trac.sagemath.org/sage_trac/ticket/10774)
Fri, 11 Feb 2011 13:40:40 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?answer=12093#post-id-12093Comment by tmonteil for <p>This certainly is weird. I think you have an indentation problem in your post, but that doesn't seem to be the problem.</p>
<p>The following is slightly simpler, but also prints the error message for me. (It also prints the error message when I use <code>except RuntimeError</code>)</p>
<pre><code>def number(expr):
try:
n = N(expr)
except:
n = 0
return n
</code></pre>
<p>Note, by contrast, that the following works without problem (no error message printed):</p>
<pre><code>def divide(n):
try:
r = 1/n
except ZeroDivisionError:
r = Infinity
return r
</code></pre>
<p>So it seems this is a bug with the recursion depth RuntimeError . . .</p>
<hr/>
<p>UPDATE: Based on the discussion, I've filed a ticked for this: <a href="http://trac.sagemath.org/sage_trac/ticket/10774">#10774</a></p>
https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=25766#post-id-25766This bug is fixed !Sat, 07 Feb 2015 22:58:28 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=25766#post-id-25766Comment by DSM for <p>This certainly is weird. I think you have an indentation problem in your post, but that doesn't seem to be the problem.</p>
<p>The following is slightly simpler, but also prints the error message for me. (It also prints the error message when I use <code>except RuntimeError</code>)</p>
<pre><code>def number(expr):
try:
n = N(expr)
except:
n = 0
return n
</code></pre>
<p>Note, by contrast, that the following works without problem (no error message printed):</p>
<pre><code>def divide(n):
try:
r = 1/n
except ZeroDivisionError:
r = Infinity
return r
</code></pre>
<p>So it seems this is a bug with the recursion depth RuntimeError . . .</p>
<hr/>
<p>UPDATE: Based on the discussion, I've filed a ticked for this: <a href="http://trac.sagemath.org/sage_trac/ticket/10774">#10774</a></p>
https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22133#post-id-22133You know, I don't think this _is_ an Exception. I think the reason we can't catch it is because it's been swallowed, and the above is just a print statement. So we'd need to find where it's being printed, and then maybe we could monkeypatch it.Fri, 11 Feb 2011 16:20:02 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22133#post-id-22133Comment by DSM for <p>This certainly is weird. I think you have an indentation problem in your post, but that doesn't seem to be the problem.</p>
<p>The following is slightly simpler, but also prints the error message for me. (It also prints the error message when I use <code>except RuntimeError</code>)</p>
<pre><code>def number(expr):
try:
n = N(expr)
except:
n = 0
return n
</code></pre>
<p>Note, by contrast, that the following works without problem (no error message printed):</p>
<pre><code>def divide(n):
try:
r = 1/n
except ZeroDivisionError:
r = Infinity
return r
</code></pre>
<p>So it seems this is a bug with the recursion depth RuntimeError . . .</p>
<hr/>
<p>UPDATE: Based on the discussion, I've filed a ticked for this: <a href="http://trac.sagemath.org/sage_trac/ticket/10774">#10774</a></p>
https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22134#post-id-22134Amusingly, complex(log(arcsin(e))) gives 0.82572700817589695+0.81223539737883776j, which works. And you can catch at least some recursion RuntimeErrors; def f(x): f(x) can be caught that way.Fri, 11 Feb 2011 15:55:45 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22134#post-id-22134Comment by John Palmieri for <p>This certainly is weird. I think you have an indentation problem in your post, but that doesn't seem to be the problem.</p>
<p>The following is slightly simpler, but also prints the error message for me. (It also prints the error message when I use <code>except RuntimeError</code>)</p>
<pre><code>def number(expr):
try:
n = N(expr)
except:
n = 0
return n
</code></pre>
<p>Note, by contrast, that the following works without problem (no error message printed):</p>
<pre><code>def divide(n):
try:
r = 1/n
except ZeroDivisionError:
r = Infinity
return r
</code></pre>
<p>So it seems this is a bug with the recursion depth RuntimeError . . .</p>
<hr/>
<p>UPDATE: Based on the discussion, I've filed a ticked for this: <a href="http://trac.sagemath.org/sage_trac/ticket/10774">#10774</a></p>
https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22135#post-id-22135Yes, I think it's a bug in Sage: running `N(log(arcsin(e)))`, or just `N(log(NaN))`, seems to send Sage into an infinite loop, hence the error. Can you catch an error produced by an infinite loop?Fri, 11 Feb 2011 15:34:31 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22135#post-id-22135Comment by niles for <p>This certainly is weird. I think you have an indentation problem in your post, but that doesn't seem to be the problem.</p>
<p>The following is slightly simpler, but also prints the error message for me. (It also prints the error message when I use <code>except RuntimeError</code>)</p>
<pre><code>def number(expr):
try:
n = N(expr)
except:
n = 0
return n
</code></pre>
<p>Note, by contrast, that the following works without problem (no error message printed):</p>
<pre><code>def divide(n):
try:
r = 1/n
except ZeroDivisionError:
r = Infinity
return r
</code></pre>
<p>So it seems this is a bug with the recursion depth RuntimeError . . .</p>
<hr/>
<p>UPDATE: Based on the discussion, I've filed a ticked for this: <a href="http://trac.sagemath.org/sage_trac/ticket/10774">#10774</a></p>
https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22132#post-id-22132In any case, I think we're agreed that it's a bug, and a ticket should be filed, right?Fri, 11 Feb 2011 16:57:19 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22132#post-id-22132Comment by DSM for <p>This certainly is weird. I think you have an indentation problem in your post, but that doesn't seem to be the problem.</p>
<p>The following is slightly simpler, but also prints the error message for me. (It also prints the error message when I use <code>except RuntimeError</code>)</p>
<pre><code>def number(expr):
try:
n = N(expr)
except:
n = 0
return n
</code></pre>
<p>Note, by contrast, that the following works without problem (no error message printed):</p>
<pre><code>def divide(n):
try:
r = 1/n
except ZeroDivisionError:
r = Infinity
return r
</code></pre>
<p>So it seems this is a bug with the recursion depth RuntimeError . . .</p>
<hr/>
<p>UPDATE: Based on the discussion, I've filed a ticked for this: <a href="http://trac.sagemath.org/sage_trac/ticket/10774">#10774</a></p>
https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22131#post-id-22131Yeah, I think both you and John are right, this is a bug.Fri, 11 Feb 2011 23:49:49 +0100https://ask.sagemath.org/question/7938/any-way-to-turn-off-error-msg-when-i-catch-the-errors/?comment=22131#post-id-22131