Categories > TinyButStrong general >

Trap MergeBlock Error

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Anthony
Date: 2011-02-21
Time: 19:41

Trap MergeBlock Error

How do we handle a MergeBlock Error that occurs when a connection to the database cannot be made. For example, I intentionally caused the connection to fail to see what MergeBlock does when no database connection is made. I get the error as follows:

TinyButStrong Error when merging block [Array]: the specified source is set to FALSE. Maybe your connection has failed.

Obviously, I do not want that to display to the end user, nor do I want the block of html related to MergeBlock to show. How do we trap such errors and prevent the html section related to the MergeBlock fields to not show.
By: Skrol29
Date: 2011-02-21
Time: 22:25

Re: Trap MergeBlock Error

Hi Anthony,

You can do something like this :
if ($sql_connection===false) {
  $TBS->MergeBlock('b', 'clear');
} else {
  $TBS->MergeBlock('b', $sql_connection, 'SELECT * FROM table1');
}

Or less readable but smarter:
$tbs_source = ($sql_connection===false) ? 'clear' : $sql_connection;
$TBS->MergeBlock('b', $tbs_source, 'SELECT * FROM table1');
By: Anthony
Date: 2011-02-22
Time: 21:11

Re: Trap MergeBlock Error

Thanks for the help. Sometimes I get a little lost wading through the manual, and at times don't quite get a handle on the explanations. I've been programming with PHP for sometime but only recently became aware of TBS. I appreciate the effort that has gone into making it and the great help it is in designing cleaner web sites.
By: Anthony
Date: 2011-02-25
Time: 21:47

Re: Trap MergeBlock Error

Well, back to MergeBlock errors and perhaps this question has been asked and answered before but after looking through the forum and manual, I don't seem to be coming up with a solution. The above solved the connection error situations, but what can I do to trap errors that are sent back by the sql connection. For example, when I get something like this:

TinyButStrong Error when merging block [eventsblock]: PostgreSQL error message when opening the query: ERROR: pg_atoi: error in "all": can't parse "all"

Obviously, I do not want that show in the browser, although I would want my code to trap that error and log it. How do we handle these errors with TBS. Using $TBS->NoErr = true suppresses the error message but the template fields output to the browser. Therefore, I need to trap the error, log it, and prevent browser from showing any merge field templates.