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 12:58:40 -0000 Organization: University of Aarhus, Department of Computer Science (DAIMI) Lines: 101 Approved: mailtonews@cs.au.dk Distribution: world Message-ID: <20000619125840.2379.qmail@noatun.mjolner.dk> Reply-To: Sascha Kimmel NNTP-Posting-Host: daimi.cs.au.dk X-Trace: xinwen.cs.au.dk 961419536 280630 255.255.255.255 (19 Jun 2000 12:58:56 GMT) X-Complaints-To: news@cs.au.dk NNTP-Posting-Date: 19 Jun 2000 12:58:56 GMT Xref: news.cs.au.dk comp.lang.beta:12422 Atle said: > Eh ... Hi, > Could someone please explain to me the difference between 'handling an exception' and 'checking the return value'. This may seem > like a horrendous question, but C++ and Java has a ver strange program flow when doing exceptions. The C++/Java way resembles > processor interrupts, whereas Beta - well it looks like the 'old' way? > Here is the old way in pseudocode ( <> Not equals ) > > 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 :) > This is opposed to 'installing error handlers' and then 'trying'. Beta seems to be in the middle between two extremes. The key seems > to lie in the returnValue semantics: I am used to seeing it as a 'value' (attribute), it will either be a legal file or some value > like -1, 0 and then some global variable, like errno will indicate what went wrong. I guess all of you know Pascal, I am used to the > IOResult way. > I was alienated by this syntax: > > 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... ;) > So, i know i will like the Beta way. But what way is it? It's the object-oriented way! :) If an error occurs a method(attribute?)/eventhandler of the corresponding file object is called. This is very much object-oriented. 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". The problem in BETA is: [...] myfile:@file(# (..now handle the different errors...) #); [...] ..code... ...more code... ... a hundred lines of code... [...] myfile.openRead; [...] I think it's more intuitive to use it the old way, e.g. in PHP: ---------X<------------------------------------------------------- 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"); ---------X<------------------------------------------------------- [Grabbed from http://www.php.net/manual/function.fopen.php] Then you simply check $fp if it's not zero. Quite simple, because you evaluate this expression/error right there where the error might occur! There are not thousands of lines between the event handling if an error occurs accessing the file and the open statement! Dear Mjolner staff, wouldn't it be very very nice if BETA would also support getting files via HTTP or FTP with a simple openRead (look, PHP can do this :)!? Regards, Sascha Kimmel