Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 852795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:39:30+00:00 2026-05-15T07:39:30+00:00

Note: I am using output buffering. It’s just wrapped in the head() and foot()

  • 0

Note: I am using output buffering. It’s just wrapped in the head() and foot() functions.

I create pages in my current PHP project by using the following template:

<?php
include 'bootstrap.php';
head();
?>

<!-- Page content here -->

<?php
foot();
?>

Is the following example an appropriate use of die()? Also, what sort of problems might this cause for me, if any?

<?php
include 'bootstrap.php';
head();

try
{
    //Simulate throwing an exception from some class
    throw new Exception('Something went wrong!');
}
catch(Exception $e)
{
    ?>
    <p>Please fix the following error:</p>
    <p><?php echo $e->getMessage(); ?></p>
    <?php
    foot();
    die();
}

//If no exception is thrown above, continue script
doSomething();
doSomeOtherThing();

foot();
?>

Basically, I have a script with multiple tasks on it and I am trying to set up a graceful way to notify the user of input errors while preventing the remaining portion of the script from executing.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:39:31+00:00Added an answer on May 15, 2026 at 7:39 am

    The whole page structure is wrong.
    Though it’s most widespread newbie mistake.

    One should never output a thing before having all data ready.
    Your script may send some HTTP headers, may set up some variables for use in the header() or anything.

    Therefore, template use is necessary.
    You have to divide your script into 2 parts – getting data part and displaying data part.
    So, you have to move header() function much lower.
    And based on the Amadan’s answer it could be

    <?php
    include 'bootstrap.php';
    try {
      getData();
    } catch (Exception $e) {
        handleError();
    }
    head();
    body();
    foot();
    ?>
    

    handleError() function may set appropriate HTTP error code (404 or 500) and substitute body template with error message text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I am not set on using VI, it is just the first thing
Note: while the use-case described is about using submodules within a project, the same
Edit: * Note: I'm using PHP 5.2 for the time being, unfortunately. I can't
NOTE: Using .NET 2.0, and VS2005 as IDE Hello all, I'm working on logging
Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables:
Note: Using raw Win32 CreateTheard() API No MFC An interface is simply a pointer
Note : No MFC No ATL Using Visual C++ While attempting a connection between
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
NOTE: I thought I was using bash, but /bin/sh is linked to /bin/dash, which
Note that this has to be on a windows box as I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.