Path: news.cs.au.dk!not-for-mail From: "Sascha Kimmel" Newsgroups: comp.lang.beta Subject: RE: exceptions: (atle // confused (# again #) atle) Date: 19 Jun 2000 17:38:48 -0000 Organization: University of Aarhus, Department of Computer Science (DAIMI) Lines: 119 Approved: mailtonews@cs.au.dk Distribution: world Message-ID: <20000619173848.8485.qmail@noatun.mjolner.dk> Reply-To: "Sascha Kimmel" NNTP-Posting-Host: daimi.cs.au.dk X-Trace: xinwen.cs.au.dk 961436343 289195 255.255.255.255 (19 Jun 2000 17:39:03 GMT) X-Complaints-To: news@cs.au.dk NNTP-Posting-Date: 19 Jun 2000 17:39:03 GMT Xref: news.cs.au.dk comp.lang.beta:12440 > -----Original Message----- > From: Atle [mailto:trollet@skynet.be] > Sent: Monday, June 19, 2000 7:02 PM > To: usergroup@mjolner.dk > Subject: Re: exceptions: (atle // confused (# again #) atle) > > > Sascha Kimmel wrote: > > > > > > > returnValue := openFile('SomeFile.bet') > > > IF returnValue <> OK > > > THEN produceError(returnValue); > > > ELSE > > > { do the normal processing. > > > returnValue will be a legal file handle } > > > ENDIF > > > > Hey, I like this code :) > But how well does it correspond to Beta exception handling? Not much... > > > > > try { > > > strm = bufferedstreamandsomestuffandtotallyunreadable > > (filename, OPENFLAGS); > > > } > > > > > > catch(...) { > > > cout << "The program has been somewhere and crashed" << > > > " difficult to say if I should recover or what?"; > > > } > > > > Plase put away this JAVA stuff... ;) > This is an example of 'dynamic exceptions' if I have understood > things right - but have I? Don't ask me much about JAVA, I've just started to look at JAVA, although I think that JAVA is not a good language for programs, only for applets! > > > So, i know i will like the Beta way. But what way is it? > > > > > > But I doubt that this is more intuitive than the "old" way which many > > languages like Perl and PHP also use. > > But object-oriented is "modern". > Problem is, I don't see the difference. It looks to me as if the > errors are handled 'as much as possible' inside the object, and Yes, inside the object, that is the difference! > that whatever isn't handled there is propagated back out to the > calling object. But there must be more to it than that? No, if you don't "catch" an exception, you BETA program will be stopped, there's no such propagation AFAIK. > > The problem in BETA is: > > > > [...] > > myfile:@file(# (..now handle the different errors...) #); > > [...] > > > > .code... > > ..more code... > > .. a hundred lines of code... > > > > [...] > > myfile.openRead; > > [...] > But errors are handled here, too. Like NoSuchFileError - I need They are HANDLED there, yes, but not DECLARED! I just wanted to show that it's sometimes very hard to see what MIGHT happen (NoSuchFileError,AccessError etc.) if you have defined these files hundreds of lines above! > to look over that again from the cat.bet example. > Jørgen, could you please add more context around your code > snippet, please? > > > > Example 1. fopen() example > > > > $fp = fopen("/home/rasmus/file.txt", "r"); > > $fp = fopen("http://www.php.net/", "r"); > > $fp = fopen("ftp://user:password@example.com/", "w"); > This, however horrifies me. > > OK in an rc file, but not in a program! RC file???? You simply do: ------------X<----------------------------------------------- $fd = fopen ("/tmp/inputfile.txt", "r"); while (!feof($fd)) { $buffer = fgets($fd, 4096); echo $buffer; } fclose ($fd); ------------X<----------------------------------------------- This is NOT a definition, $fp ($fd) simply is the file HANDLE! In PHP and Perl you do not need to define any variables, variables have no specific type and are handled context-sensitive! Regards, Sascha Kimmel