diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2016-02-21 12:28:13 +0100 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2016-02-21 12:28:13 +0100 |
| commit | 7cab8a5006da807d83f427217e2158079bb78145 (patch) | |
| tree | 8d55377133839458dba7ff55b494146ab667e31d | |
| parent | 7c1df8a7cd4271309160abfd28fb8011a3fee46f (diff) | |
| download | luasocket-7cab8a5006da807d83f427217e2158079bb78145.tar.gz luasocket-7cab8a5006da807d83f427217e2158079bb78145.tar.bz2 luasocket-7cab8a5006da807d83f427217e2158079bb78145.zip | |
Update comment in except.h
| -rw-r--r-- | src/except.h | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/except.h b/src/except.h index 1e7a245..2497c05 100644 --- a/src/except.h +++ b/src/except.h | |||
| @@ -9,21 +9,26 @@ | |||
| 9 | * error checking was taking a substantial amount of the coding. These | 9 | * error checking was taking a substantial amount of the coding. These |
| 10 | * function greatly simplify the task of checking errors. | 10 | * function greatly simplify the task of checking errors. |
| 11 | * | 11 | * |
| 12 | * The main idea is that functions should return nil as its first return | 12 | * The main idea is that functions should return nil as their first return |
| 13 | * value when it finds an error, and return an error message (or value) | 13 | * values when they find an error, and return an error message (or value) |
| 14 | * following nil. In case of success, as long as the first value is not nil, | 14 | * following nil. In case of success, as long as the first value is not nil, |
| 15 | * the other values don't matter. | 15 | * the other values don't matter. |
| 16 | * | 16 | * |
| 17 | * The idea is to nest function calls with the "try" function. This function | 17 | * The idea is to nest function calls with the "try" function. This function |
| 18 | * checks the first value, and calls "error" on the second if the first is | 18 | * checks the first value, and, if it's falsy, wraps the second value in a |
| 19 | * nil. Otherwise, it returns all values it received. | 19 | * table with metatable and calls "error" on it. Otherwise, it returns all |
| 20 | * values it received. Basically, it works like the Lua "assert" function, | ||
| 21 | * but it creates errors targeted specifically at "protect". | ||
| 20 | * | 22 | * |
| 21 | * The protect function returns a new function that behaves exactly like the | 23 | * The "newtry" function is a factory for "try" functions that call a |
| 22 | * function it receives, but the new function doesn't throw exceptions: it | 24 | * finalizer in protected mode before calling "error". |
| 23 | * returns nil followed by the error message instead. | ||
| 24 | * | 25 | * |
| 25 | * With these two function, it's easy to write functions that throw | 26 | * The "protect" function returns a new function that behaves exactly like |
| 26 | * exceptions on error, but that don't interrupt the user script. | 27 | * the function it receives, but the new function catches exceptions thrown |
| 28 | * by "try" functions and returns nil followed by the error message instead. | ||
| 29 | * | ||
| 30 | * With these three functions, it's easy to write functions that throw | ||
| 31 | * exceptions on error, but that don't interrupt the user script. | ||
| 27 | \*=========================================================================*/ | 32 | \*=========================================================================*/ |
| 28 | 33 | ||
| 29 | #include "lua.h" | 34 | #include "lua.h" |
