Commit 74940254 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Raise errors, no bare exceptiosn

parent 57fd2a34
......@@ -23,13 +23,16 @@ class telescope():
'J2000' or 'AZEL'.
'''
if setmode not in ('J2000', 'AZEL', None):
raise Exception("Mode must be None, 'J2000' or 'AZEL', not " + mode)
raise ValueError("Mode must be None, 'J2000' or 'AZEL', not " + mode)
self.setmode = setmode
if consoleHost is None:
consoleHost = config.get('Console','HostName')
if consoleHost == 'console':
if socket.hostname=="mercurius":
logging.warning("You are using the actual console, not a demo!")
else:
raise ValueError("Talking to the actual console can only be done from mercurius")
self.dist_az = None
self.dist_el = None
......@@ -75,13 +78,13 @@ class telescope():
self._j2000socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._j2000socket.connect((consolehost, j2000_read_port))
except socket.error:
raise Exception("Cannot connect to j2000 status server")
raise IOError("Cannot connect to j2000 status server")
while True:
readable, writable, exceptional = select.select(
[self._j2000socket], [], [])
if len(exceptional)>0:
raise Exception("Error with j2000 read socket")
raise IOError("Error with j2000 read socket")
msg = readable[0].recv(4096).decode("UTF-8")
vals = msg.strip().split()
(ra, dec) = (vals[2], vals[3])
......@@ -98,13 +101,13 @@ class telescope():
self._tracesocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._tracesocket.connect((tracehost, traceport))
except socket.error:
raise Exception("Cannot connect to trace2port server")
raise IOError("Cannot connect to trace2port server")
while True:
readable, writable, exceptional = select.select(
[self._tracesocket], [], [])
if len(exceptional)>0:
raise Exception("Error with trace read socket")
raise IOError("Error with trace read socket")
msg = readable[0].recv(4096).decode("UTF-8")
vals = msg.strip().split()
self.az = (float(vals[0])*u.rad).to(u.deg)
......@@ -123,7 +126,7 @@ class telescope():
setpoint can be an astropy SkyCoord or a tuple (ra,dec) in radians
'''
if self.setmode != 'J2000':
raise Exception("Cannot set Ra/Dec if mode is not J2000")
raise ValueError("Cannot set Ra/Dec if mode is not J2000")
if not isinstance(setpoint, SkyCoord):
coord = SkyCoord(ra =setpoint[0] * u.radian,
......@@ -143,7 +146,7 @@ class telescope():
setpoint should be a tuple of degrees or of astropy Quantity
'''
if self.setmode != 'AZEL':
raise Exception("Cannot set Az/El if mode is not AZEL")
raise ValueError("Cannot set Az/El if mode is not AZEL")
(az, el) = setpoint
if isinstance(az, u.Quantity):
......@@ -162,7 +165,7 @@ class telescope():
offset should be a tuple of degrees or of astropy Quantity
'''
if self.setmode is None:
raise Exception("Cannot set offset if mode is None")
raise ValueError("Cannot set offset if mode is None")
(off_az, off_el) = offset
if isinstance(off_az, u.Quantity):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment