Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
The bucket brigade approach to putting out a fire is to pass buckets of water along a chain of people.
Many programmers use the bucket brigade approach to error handling.
Note: This is easier for programs that can return multiple results, or those that more easily support reference parameters.
Note: The variable ec for "error code" is used where a zero indicates no error and non-zero provides the error code of what happened.
Here is the Python code.
Here is the output of the Python code.
3. Exception handling
The bucket brigade is a MTTF (Mean Time To Failure) approach that attempts to find and handle any error that might be encountered.
4. Python code
Here is the Python code.
5. Python output
Here is the output of the Python code.
Note that Python has various types of exceptions that can be used.
Is is also possible to raise an exception via code.
6. JavaScript code
Here is the JavaScript code.
7. JavaScript output
Here is the output of the JavaScript code.
Notice that JavaScript does not actually catch the exception. It keeps on going.
In JavaScript, a division by zero is defined. It is Infinity for "infinity"!
8. PHP code
Here is the PHP code.
9. PHP output
Here is the output of the PHP code.
Notice that PHP does not actually catch the exception. It keeps on going.
In PHP, a division by zero is defined. It is INF for "infinity"!
10. Raising errors
Most programming languages allow the programmer to raise exceptions and then handle those exceptions.