PHP Classes

File: docs/TryCatchMgr.md

Recommend this page to a friend!
  Classes of Kjell-Inge Gustafsson   PcGen   docs/TryCatchMgr.md   Download  
File: docs/TryCatchMgr.md
Role: Example script
Content type: text/markdown
Description: 1.1.45
Class: PcGen
Generate PHP code from parameters
Author: By
Last change: 1.1.47
Date: 3 years ago
Size: 2,853 bytes
 

Contents

Class file image Download

[comment]: # (This file is part of PcGen, PHP Code Generation support package. Copyright 2020 Kjell-Inge Gustafsson, kigkonsult, All rights reserved, licence GPL 3.0)

TryCatchMgr

The `TryCatchMgr` manages try-catch expression

  • try-body code is set using TryCatchMgr::setBody()
  • catch-bodies code are set using (single) TryCatchMgr::appendCatch() (array) TryCatchMgr::setCatch()

Constants :

  • CatchMgr::EXCEPTION
  • CatchMgr::RUNTIMEEXCEPTION
  • CatchMgr::INVALIDARGUMENTEXCEPTION

But any string accepted...

TryCatchMgr Methods

Inherited [Common methods]


* Set trybody with 'Exception'-catch and body
* ```tryBody``` _string_|_string[]_   code
* ```catchBody``` _string_|_string[]_ code
* Return _static_
* Throws _InvalidArgumentException_

---

  • Return _array_, result code rows (null-bytes removed) no trailing eol
  • Throws _RuntimeException_

* Return _array_, result code rows (null-bytes removed) no trailing eol
* Throws _RuntimeException_

---

  • Return _bool_ true if set, false not

* Append single exception with code-body
* ```exception``` _string_  or constant
* ```catchBody``` _string_|_string[]_ code
* Return _static_
* Throws _InvalidArgumentException_


  • Append exceptions with code-body
  • * _string_ (Exception)
    * _string_ (Exception), catchBody
    
    
  • Return _static_
  • Throws _InvalidArgumentException_

Example

<?php

$code = FcnFrameMgr::init()
    ->setName( 'someFunction' )
    ->setBody(
        TryCatchMgr::init()
            ->setBody( ' /here comes some code..../' )
            ->setCatch(
                [
                    [ CatchMgr::INVALIDARGUMENTEXCEPTION, ' /here comes some code..../' ],
                    CatchMgr::factory( 'LogicException', ' /here comes some code..../' ),
                    [ CatchMgr::RUNTIMEEXCEPTION, ' /here comes some code..../' ],
                    CatchMgr::EXCEPTION
               ]
            ->toArray()
    )
    ->toString();

Result :

    public function someFunction()
    {
        try {
             /here comes some code..../
        }
        catch( InvalidArgumentException $e ) {
             /here comes some code..../
        }
        catch( LogicException $e ) {
             /here comes some code..../
        }
        catch( RuntimeException $e ) {
             /here comes some code..../
        }
        catch( Exception $e ) {
        }
    }

<small>Return to [README] - [Summary]</small>

[Common methods]:CommonMethods.md [README]:../README.md [Summary]:Summary.md