I have actually watched this number of times. A methos is returning 0, 1 or -1.public int getNumber(Documents f) attempt FileInputStream fin = brand-new FileInputStream(f); BufferedReader br = new BufferedReader(new InputStreamReader(fin), "ASCII"); String line = br.readLine(); line = line.trim(); int number = Integer.parseInt(line); br.close(); rerevolve number; capture (FileNotFoundException fnf) // Oh dear, error arisen opening file displayErrorMessage(fnf.getMessage()); catch (IOException ioex) displayErrorMessage(ioex.getMessage()); catch (NumberFormatException nfe) displayErrorMessage("The file included invalid data"); return -1; // If we obtain right here, we didn"t review a // number from the fileWhat actually does it suppose when it states return -1 in this strategy OR any various other number ?
Saloon Keeper
posted 10 years ago
*
1
*
*

It suggests the author of the approach does not appreciate exceptions appropriately. They are probably offered to programming in a language favor C, wright here clients of a technique are usually notified of errors through some distinct rerotate worth. In greater programming language we usage exceptions rather.

You are watching: What does return 1 mean in c


Marshal
posted 10 years ago
This code will certainly not even compile, bereason class BufferedReader does not have a constructor that takes a Reader and also a String, as you are trying to usage in line 4.
so what will -1 execute ? Does it mean something special ? What if 0 or 1 is reverted ? I think I had seen 0 and also 1 being went back (I am not sure) Can any value be changed (2, 3 4,...........) OR it has to be any one from -1, 0 or 1 just ? If so, why ? I am just trying to number out usage of reverted value and have actually duplicated code from somewbelow. I have actually not run it. Thanks

nirjari patel wrote:so what will -1 execute ?

That depends totally on the code that calls this one. All this does is rerevolve it. This method deserve to rerotate any integer. It tries to check out an integer from a file. That could contain 0, 1, -284, 8263, and so on If there"s a trouble reading the number it will rerotate -1 (however it will likewise return -1 if the file actually includes "-1").
Back in the "old days", you would frequently use a return value of a technique to tell you if points worked. Often 0 or greater would certainly expect points were OK, and particular values might tell you even more specific things. a negative value expected somepoint went horribly wrong, and again, the specific worth can tell you what that was. This required you to KNOW what those worths suppose, so hopefully the perkid who composed the function you are calling gave good documentation...and also that the feature hadn"t readjusted.

Tbelow are only two tough things in computer science: cache invalidation, naming things, and also off-by-one errors


That depends completely on the code that calls this one. All this does is rerevolve it.

See more: The Spreading Of Soccer Around The World Is An Example Of Cultural __________.

That indicates I have the right to put any number in here and also if file does not rerotate number, then number I have mentioned will be reverted.

Often 0 or greater would expect things were OK, and particular values could tell you even more particular things. an unfavorable worth expected something went horribly wrong, and aobtain, the particular worth can tell you what that was

"Providing 0 or higher , once things are ok and giving negative value, once points are wrong" , is this convention or is it syntaxes ? Thanks

nirjari patel wrote: . . . "Providing 0 or better , when things are ok and offering negative value, when points are wrong" , is this convention or is it syntaxation ? Thanks

Convention. There is one more convention, still offered by System.exit() that 0 indicates all well and also any other value implies points are wrong.
What really matters is that the approach have to occupational as recorded. If the documentation says that the technique should rerotate -1 to signal an error problem, that does commonly suggest a negative design decision, yet the method is bound to adbelow to the spec. There are several instances where returning -1 or various other negative worth is justifiably offered to signal a singular non-error state/condition. Examples: String#indexOf / lastIndexOf, DefaultSingleSelectionModel#getSelectedIndex, Image#getWidth / getHeight, GraphicsDevice#getAvailableAcceleratedMemory