Robin's Blog

Get more detailed messages for maths errors in IDL

I’ve just discovered something that I feel I must share here – partly to make more people aware of it, and partly so I don’t forget it. In the IDL programming language you will sometimes find your program interrupted by a line saying something like:

% Program caused arithmetic error: Floating divide by 0

Sometimes it will be obvious where the error is – but often you can spend ages looking for it (just like with segfaults in C…). What I only just found out is that if you run the command

!EXCEPT=2

At the IDL prompt before running your program you will get a far more informative error message like

% Program caused arithmetic error: Floating divide by 0
% Detected at JUNK 3 junk.pro

The key thing is that this tells you what line the error occurred on (line 3 of junk.pro in the above example) – which helps you to narrow down the problem far more quickly.

More details on the values that !EXCEPT can take is available here – basically the options are no messages, unhelpful messages and helpful messages.

This is very useful – but just beware that running with !EXCEPT=2 all the time will slow down your code, so only do it if you need to for debugging purposes.


Categorised as: Computing, IDL, Programming


Leave a Reply

Your email address will not be published.