Help with Exceptions on I/O
Alexandre Weffort Thenorio
alethenorio@home.se
Wed, 13 Aug 2003 01:17:07 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0050_01C36138.9CCF25B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I have a program which creates textfiles out of other files. Since the
program is runned from windows I output some text strings (Like "File
created succefully") and I need to stop the program before it quits so =
that
the user can read the line outputted to know what went on and then he =
can
press ENTER to quit the program.
I managed to do this fine if no error occurs but when a error occurs I =
am
having problems.
The code goes like that
main :: IO()
main =3Dcatch (do
Do all the needed stuff here
putStr "File created Successfully. Press RETURN to
quit"
dummy <- getLine --Halts the program so the user =
can
read the above line)
putStr "Exiting now..." --needed since I can't =
finish a
do function with the "dummy<- getLine" line) (\_ -> do putStr "\nFile =
not
found. Press RETURN (ENTER) to quit."
dumb <- getLine
putStr "\nExiting...")
So when the program runs, if the input file is found the program writes
successfull creation of file but if the file doesn't exist, after the =
user
gives the input filename and press enter, the program creates a new line =
and
Halts (Probably because of the getLine function) without writing out
anything, then when the user press ENTER again it writes the line at the
first putStr (File not...), then writes the next putStr line under it
(Exiting...) and exits. I don't know why it doesn't wirte the first =
line,
halts and then when user press enter it writes the second and quits.
Can anybody help me as I am not very familiar with exception and =
catches.
Another question I have is: Is there any other function rather than =
getLine
that halts a program and continues when a user press any key (Instead of
ENTER) and besides this is an ugly code since getLine wasn't made for =
that
but I couldn't find anything else myself.
Thank you in advance.
Best Regards
Alex
------=_NextPart_000_0050_01C36138.9CCF25B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>I have a program which creates textfiles out of =
other=20
files. Since the<BR>program is runned from windows I output some text =
strings=20
(Like "File<BR>created succefully") and I need to stop the program =
before it=20
quits so that<BR>the user can read the line outputted to know what went =
on and=20
then he can<BR>press ENTER to quit the program.<BR><BR>I managed to do =
this fine=20
if no error occurs but when a error occurs I am<BR>having =
problems.<BR><BR>The=20
code goes like that<BR><BR>main :: IO()<BR>main =3Dcatch=20
(do<BR> =
=20
Do all the needed stuff=20
here<BR>  =
; =20
putStr "File created Successfully. Press RETURN=20
to<BR>quit"<BR> &nbs=
p; =20
dummy <- getLine --Halts the program so the user can<BR>read the =
above=20
line)<BR> &nbs=
p; =20
putStr "Exiting now..." --needed since I can't finish a<BR>do function =
with the=20
"dummy<- getLine" line) (\_ -> do putStr "\nFile not<BR>found. =
Press=20
RETURN (ENTER) to quit."<BR> dumb <-=20
getLine<BR> putStr "\nExiting...")<BR><BR>So =
when the=20
program runs, if the input file is found the program =
writes<BR>successfull=20
creation of file but if the file doesn't exist, after the user<BR>gives =
the=20
input filename and press enter, the program creates a new line =
and<BR>Halts=20
(Probably because of the getLine function) without writing =
out<BR>anything, then=20
when the user press ENTER again it writes the line at the<BR>first =
putStr (File=20
not...), then writes the next putStr line under it<BR>(Exiting...) and =
exits. I=20
don't know why it doesn't wirte the first line,<BR>halts and then when =
user=20
press enter it writes the second and quits.<BR><BR>Can anybody help me =
as I am=20
not very familiar with exception and catches.<BR><BR><BR>Another =
question I have=20
is: Is there any other function rather than getLine<BR>that halts a =
program and=20
continues when a user press any key (Instead of<BR>ENTER) and besides =
this is an=20
ugly code since getLine wasn't made for that<BR>but I couldn't find =
anything=20
else myself.<BR><BR>Thank you in advance.<BR><BR>Best =
Regards<BR><BR>Alex
<DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML>
------=_NextPart_000_0050_01C36138.9CCF25B0--