
Hi all, I have some code (basically from http://sequence.complete.org/node/257) which has: import Control.Exception (finally, catch, Exception (..), IOException) ... handler (IOException e) | isEOFError e = return () but gch-6.10.3 still says Not in scope: data constructor `IOException' Someone smack me with the cluestick please :-). Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

Am Sonntag 14 Juni 2009 01:58:06 schrieb Erik de Castro Lopo:
Hi all,
I have some code (basically from http://sequence.complete.org/node/257) which has:
import Control.Exception (finally, catch, Exception (..), IOException)
...
handler (IOException e)
| isEOFError e = return ()
but gch-6.10.3 still says
Not in scope: data constructor `IOException'
Someone smack me with the cluestick please :-).
a) you only imported the type, not the data constructor(s) b) confusingly, the constructor of IOException is IOError: data IOException = IOError { ioe_handle :: Maybe Handle, -- the handle used by the action flagging -- the error. ioe_type :: IOErrorType, -- what it was. ioe_location :: String, -- location. ioe_description :: String, -- error type specific information. ioe_filename :: Maybe FilePath -- filename the error is related to. } deriving Typeable instance Exception IOException
Cheers, Erik

Daniel Fischer wrote:
a) you only imported the type, not the data constructor(s) b) confusingly, the constructor of IOException is IOError:
data IOException = IOError { ioe_handle :: Maybe Handle, -- the handle used by the action flagging -- the error. ioe_type :: IOErrorType, -- what it was. ioe_location :: String, -- location. ioe_description :: String, -- error type specific information. ioe_filename :: Maybe FilePath -- filename the error is related to. } deriving Typeable
instance Exception IOException
Ok, I can see whats wrong, but I still have no idea how to fix it. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

Am Sonntag 14 Juni 2009 06:33:07 schrieb Erik de Castro Lopo:
Daniel Fischer wrote:
a) you only imported the type, not the data constructor(s) b) confusingly, the constructor of IOException is IOError:
data IOException = IOError { ioe_handle :: Maybe Handle, -- the handle used by the action flagging -- the error. ioe_type :: IOErrorType, -- what it was. ioe_location :: String, -- location. ioe_description :: String, -- error type specific information. ioe_filename :: Maybe FilePath -- filename the error is related to. } deriving Typeable
instance Exception IOException
Ok, I can see whats wrong, but I still have no idea how to fix it.
Erik
Ah, I didn't follow the link yesterday, that code is from 2007. With ghc-6.10, Control.Exception has been revamped, Exception is no longer a datatype but a type class. Before 6.10, IOException was a constructor of Exception. Simple solution: import Control.OldException instead of Control.Exception Harder long-time solution: rewrite the code to work with the new system. I would first use the simple solution and then see whether it's worth the rewrite. Cheers, Daniel

Daniel Fischer wrote:
Simple solution: import Control.OldException instead of Control.Exception
I actually already had that working :-).
Harder long-time solution: rewrite the code to work with the new system.
This is what I'd like to do. Is there a guide or howto for converting from OldException to Exception?
then see whether it's worth the rewrite.
As a learning exercise I thin it is :-). Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

Am Montag 15 Juni 2009 00:29:27 schrieb Erik de Castro Lopo:
Daniel Fischer wrote:
Simple solution: import Control.OldException instead of Control.Exception
I actually already had that working :-).
D'oh
Harder long-time solution: rewrite the code to work with the new system.
This is what I'd like to do. Is there a guide or howto for converting from OldException to Exception?
I don't know of one. You could use the SomeException type and have handler e = case fromException e of Just e' | isEOFError e' -> return () _ -> print e or you could only handle IOExceptions, handler e | isEOFError e = return () | otherwise = print e either way, you must somehow determine which type of exception "throwTo mainTID" in spawn throws, in the first case its type would be (SomeException -> IO ()), in the second (IOException -> IO ()). For the first case, it would probably better to have act `catch` (throwTo mainTID . toException) in spawn.
then see whether it's worth the rewrite.
As a learning exercise I thin it is :-).
I agree.
Erik
participants (2)
-
Daniel Fischer
-
Erik de Castro Lopo