Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18401

Re: STDERR vs Exception

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: STDERR vs Exception
Date 2020-11-14 12:22 -0500
Organization A noiseless patient Spider
Message-ID <rop3nq$efb$1@jstuckle.eternal-september.org> (permalink)
References <rolkdn$12ss$1@gioia.aioe.org>

Show all headers | View raw


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
==================

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web