Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18400 > unrolled thread
| Started by | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| First post | 2020-11-13 10:42 +0100 |
| Last post | 2020-11-15 10:21 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.php
STDERR vs Exception alex <1j9448a02@lnx159sneakemail.com.invalid> - 2020-11-13 10:42 +0100
Re: STDERR vs Exception Jerry Stuckle <jstucklex@attglobal.net> - 2020-11-14 12:22 -0500
Re: STDERR vs Exception alex <1j9448a02@lnx159sneakemail.com.invalid> - 2020-11-15 10:21 +0100
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2020-11-13 10:42 +0100 |
| Subject | STDERR vs Exception |
| Message-ID | <rolkdn$12ss$1@gioia.aioe.org> |
// EXAMPLE1 fwrite(STDERR, ...); exit(...); // EXAMPLE2 throw new \Exception(...); In what situations to use EXAMPLE1 or EXAMPLE2?
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2020-11-14 12:22 -0500 |
| Message-ID | <rop3nq$efb$1@jstuckle.eternal-september.org> |
| In reply to | #18400 |
On 11/13/2020 4:42 AM, alex wrote: > // EXAMPLE1 > fwrite(STDERR, ...); > exit(...); > > // EXAMPLE2 > throw new \Exception(...); > > In what situations to use EXAMPLE1 or EXAMPLE2? Your first example simply writes a message to STDERR and terminates. Your second example must be in a try/catch block. It allows you to define the type of exception which occurred and catch the exception. In your exception handler you can analyze the problem, attempt to correct it if possible and take any other actions you may deem appropriate. When an exception is thrown, processing immediately stops in that try block and control passes to the first catch block matching the exception. If there is no matching catch block, processing terminates. The example at https://www.php.net/manual/en/language.exceptions.php is not the best - there are better examples in other languages such as C++ and Java but not knowing your experience I hesitate to recommend other languages. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2020-11-15 10:21 +0100 |
| Message-ID | <roqrvi$14nm$1@gioia.aioe.org> |
| In reply to | #18401 |
Il 14/11/20 18:22, Jerry Stuckle ha scritto: > On 11/13/2020 4:42 AM, alex wrote: >> // EXAMPLE1 >> fwrite(STDERR, ...); >> exit(...); >> >> // EXAMPLE2 >> throw new \Exception(...); >> >> In what situations to use EXAMPLE1 or EXAMPLE2? > > Your first example simply writes a message to STDERR and terminates. > > Your second example must be in a try/catch block. It allows you to > define the type of exception which occurred and catch the exception. In > your exception handler you can analyze the problem, attempt to correct > it if possible and take any other actions you may deem appropriate. > > When an exception is thrown, processing immediately stops in that try > block and control passes to the first catch block matching the > exception. If there is no matching catch block, processing terminates. > > The example at https://www.php.net/manual/en/language.exceptions.php is > not the best - there are better examples in other languages such as C++ > and Java but not knowing your experience I hesitate to recommend other > languages. > > Thanks :)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web