answersLogoWhite

0


Best Answer

When the error is not critical, for instance, if you divide by zero you should handle it throw exceptions. A good example for to return an error code is when you cannot establish connection with server. If you have established connection and lost it, it's better too use exceptions.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When would you choose to return an error code rather than throw an exception?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is error and exception same?

Error: Any departure from the expected behavior of the system or program, which stops the working of the system is an error. Exception:Any error or problem which one can handle and continue to work normally. Note that in Java a compile time error is normally called an "error," while a runtime error is called an "exception." Errors don't have subclasses while exception has two subclasses, they are compile time exception or checked exception (ClassNotFound Exception, IOException, SQLException etc.) and runtime or unchecked exception(ArrayIndexOutOfBounds Exception, NumberFormat Exception).


Difference between run time error and run time exception in java?

Runtime Error Cannot be Rectified but Runtime Exception can.


What are the main differences between user-defined exceptions and system-defined exception?

Systems don't throw exceptions. System errors are low-level errors which you have to detect programmatically. In C, most functions that cause system errors will typically return -1 to indicate an error has occurred and 0 to indicate no error. If an error occurs, you should examine the global errno variable to determine the actual error code (as defined in <errno.h>). You can use the strerror() function to obtain a pointer to the string representation of the error, and perror() to display the error. If you cannot handle the error there and then, then you should pass the error to your error handling code. Languages that support exception handling make it easy to pass errors from the point they are detected to a point where they can be handled. Simply transform the error code into an exception object and then throw the object, allowing the exception handling mechanism to deal with it.


How do you use exception in c sharp?

Exceptions are the error handling mechanism of C#. When an error occurs, an exception is thrown using this syntax: void BadMethod() { bool Error = true; if (Error) { throw new Exception("Whoops!"); } } Methods can then handle exceptions using a try/catch/finally syntax. The code that you are trying to execute goes between a try { } block, the code to handle the error goes between the catch { } block. Any code that you put between the finally { } block will always execute after the exception handling code is complete (or if an error did not occur). void test() { try { BadMethod(); catch (Exception ex) { Console.WriteLine("An error occured. The description is: " + ex.Description); } finally { Console.WriteLine("I'm done!"); } }


How exception handling is different from error?

we know that exception can happen ..but we dont know about errors .. we dont have knowledge about them in already ...but in case of exception we take some prevential actions and put already an exception block to catch that exception


Does php5 support exception?

try{ answer('yes, yes it does.'); }catch(Exception $e){ echo "errr.... error dude: " . $e; }


What does programming error-exception occurred mean on DVD shrink?

A program error exception in ANY program means that some error occured in the program that was unexpected, hence the word "exception" here. An error that a program expects might happen wouldn't be an exception per se, and it would be programmed to deal with that. You might try to update to a newer version of the program that might have a fix built into it to deal with that, or post a bug report (if it's repeatable) on the creator's website so they know that issue exists.


What is exception handling in C plus plus?

Exception handling is the means by which exceptions -- anomalous events -- are resolved without causing a runtime error.


Why you handle exception in java?

Exception handling helps us catch or identify abnormal scenarios in our code and handle them appropriately instead of throwing up a random error on the front-end (User Interface) of the application. Exception handling allows developers to detect errors easily without writing special code to test return values. Even better, it lets us keep exception-handling code cleanly separated from the exception-generating code. It also lets us use the same exception-handling code to deal with a range of possible exceptions


Does exception always signal an error?

It depends on exactly how you define an error. If an exception is thrown, then it means something has gone wrong. Some Exceptions, such as a NullPointerException, will almost certainly signal an error in your code or data. Others, such as IOExceptions, can be caused by things outside your control, and would probably not be considered errors.


What is exception and list some of the common type of exception?

Exceptions are thrown when Java encounters an error. They are a fundamental part of the Java error handling system. In a nutshell, Java will throw an Exception when it encounters an error so that an exception handler can "handle" the error. For instance, if a calculator program is given the command "1/0", Java can throw an ArithmeticException which could be reported back to the user.Some common types are:ArithmeticException - thrown when arithmetic error has occurred, like dividing by 0IOException - thrown when an input or output error has occurred, like a file not foundArrayIndexOutOfBoundsException - thrown when a nonexistent element of an array is requested, like arr[-1]NullPointerException - thrown when some operation if performed on an object whose value is nll.


Advantages of Exception handling in java?

Exception handling helps us catch or identify abnormal scenarios in our code and handle them appropriately instead of throwing up a random error on the front-end (User Interface) of the application. Exception handling allows developers to detect errors easily without writing special code to test return values. Even better, it lets us keep exception-handling code cleanly separated from the exception-generating code. It also lets us use the same exception-handling code to deal with a range of possible exceptions.