Ask Your Question

any way to turn off error msg when I catch the errors?

asked 2011-02-11 06:19:00 -0500

Shu gravatar image

updated 2015-02-07 15:51:34 -0500

tmonteil gravatar image

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
sage: a.is_NaN()
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2011-02-11 06:40:40 -0500

niles gravatar image

updated 2011-02-12 01:27:50 -0500

This 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):
        n = N(expr)
        n = 0
    return n

Note, by contrast, that the following works without problem (no error message printed):

def divide(n):
        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

edit flag offensive delete link more


Yes, 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?

John Palmieri gravatar imageJohn Palmieri ( 2011-02-11 08:34:31 -0500 )edit

Amusingly, 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.

DSM gravatar imageDSM ( 2011-02-11 08:55:45 -0500 )edit

You 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.

DSM gravatar imageDSM ( 2011-02-11 09:20:02 -0500 )edit

In any case, I think we're agreed that it's a bug, and a ticket should be filed, right?

niles gravatar imageniles ( 2011-02-11 09:57:19 -0500 )edit

Yeah, I think both you and John are right, this is a bug.

DSM gravatar imageDSM ( 2011-02-11 16:49:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-02-11 06:19:00 -0500

Seen: 924 times

Last updated: Feb 12 '11