Tag Archive - Code

include vs. include_once vs. require vs. require_once

include (‘sponsor_links.php’);
If the file sponsor_links is present in the current folder, it will be included ( way may want it to appear both – at the top and at the bottom).

include_once (‘statistics.php’);
If the file statistics.php is present, it means we want statistics for the page. Otherwise, we don’t want statistics. Deleting statistics.php will not affect the main program.

require (‘navigation.php’);
We may want to include the navigational links both both at the top and the bottom at the page. If navigation.php is not present, the main program will stop running and an error message will be displayed.

require_once (‘google_adsense_top.php’);
Because a page has only one top, only one instance of google_adsense_top.php will be included. If google_adsense_top.php is not present, the main program will stop running and an error message will be displayed.

ColdFusion Try and Catch

In order for your code to directly handle an exception, the tags in question must appear within a cftry block. It is a good idea to enclose an entire application page in a cftry block. You then follow the cftry block with cfcatch blocks, which respond to potential errors. When an exception occurs within the cftry block, processing is thrown to the cfcatch block for that type of exception.

Here is an outline for using cftry and cfcatch to handle errors:

<cftry>
   Put your application code here ...
   <cfcatch type="exception type1">

      Add exception processing code here ...
   </cfcatch>
   <cfcatch type="exception type2">
      Add exception processing code here ...
   </cfcatch>

   ...
   <cfcatch type="Any">
      Add exception processing code appropriate for all other exceptions
here ...
   </cfcatch>
</cftry>