
28 Aug
2001
28 Aug
'01
2:53 p.m.
I also haven't yet worked out how to tell if a string is "read"able or not, yet - if (read "45")::Integer or whatever gives an error (e.g. if I'd put "af" instead of "45"), it seems to be pretty uncatchable, which is a pain. How do I tell if an instance of reading will work, or catch that it didn't?
In GHC, you can do this: import Exception do result <- catch (evaluate (read "foo" :: Int)) (\error -> ... ) but unfortunately read doesn't raise a useful exception (just error "Prelude.read: no parse"), so you can't filter it very easily. However I don't think that read is likely to raise any other exceptions. Cheers, Simon