[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] SWIG, current gr-howto structure and exception sp
From: |
Martin Braun |
Subject: |
Re: [Discuss-gnuradio] SWIG, current gr-howto structure and exception specifiers |
Date: |
Tue, 5 Jun 2012 14:58:45 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Sun, Jun 03, 2012 at 10:22:14AM -0400, Tom Rondeau wrote:
> On the other hand, I thought all standard exceptions were passed
> properly through SWIG to Python already. I was under the impression
> that if you're header file declares that it throws, then you can catch
> it in Python. If that's not the case, then we should try to figure out
> an easy way to handle that.
Hi Tom and rest,
so, I didn't do my research properly (partly): Exceptions *are* caught by
SWIG, *but* they always end up as RuntimeErrors, regardless of what the
exception type was in C++.
So, for future reference:
If you throw a std::invalid_argument in a block constructor, it ends
up as a RuntimeError in Python. If you hand-edit the SWIG file and add
an exception specifier, it ends up as a ValueError, which I think is the
better behaviour, and it would be great if SWIG did this automatically.
But frankly, I don't think this is that big a deal, I'll just catch
RuntimeErrors instead of ValueErrors. Or edit .i-files.
There's just no "clean" way to do this, because you'd either have to
specify the exceptions in the header (which is deprecated C++), write a
.i (redundant) or lose the exception type.
MB
--
Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)
Dipl.-Ing. Martin Braun
Research Associate
Kaiserstraße 12
Building 05.01
76131 Karlsruhe
Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu
KIT -- University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association