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 6100507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:23:41+00:00 2026-05-23T13:23:41+00:00

The functions I have written are throwing exceptions if they can’t do their job.

  • 0

The functions I have written are throwing exceptions if they can’t do their job. For the productive environment I thought to redirect the exception to a nice looking error page. Therefore I’m thinking of setting the exception handler set_exception_handler on the beginning of every script. How does the error page know which error occured? I thought of putting an error code into the URL like header("Location: error.php?code=1234"). While in the development phase I just would not set the exception handler, thus every exception would be printed onto the php default error screen Uncaugt Exception: … with all usefull informations.

I have read Exceptions in PHP – Try/Catch or set_exception_handler? but don’t know how to write a front controller script and also think this is maybe to much the effort.

I’m a PHP beginner who likes to handle errors in the right way, but I’m just not sure if I’m doing it right or wrong. Do you think it’s ok doing it like above described or do you have other suggestions?

Thank you!

  • 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-23T13:23:42+00:00Added an answer on May 23, 2026 at 1:23 pm

    Don’t redirect. In your exception handler function just output the error page at that point (or include a PHP file which includes the error page HTML). You also want to set an appropriate status code (using the PHP header function).

    Edit: Why not to redirect:

    • You want to return an appropriate HTTP status code on your error pages (usually 404, 403, 400, 500 or 503 depending on the cause), so that search engine robots know not to index the error, crawlers can identify broken pages, browsers know not to cache the page and so on. If you redirect, you are returning a 301/302 HTTP status code and not one of the error ones.
    • You want users to be able to refresh the page with the error on, in case it was a temporary glitch. If you redirect them to another URL, however many times they refresh they will always see your error page (since that’s the page they’re on).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For our online game, we have written tons of PHP classes and functions grouped
I have written a set of javascript functions that allow me to validate user
I have written a function that gets a given number of random records from
I have a function I've written that was initially supposed to take a string
I have a simple function written in Oracle 9i (version 9.2.0.4.0) to simulate an
I want to make sure that a set of functions have the same signature
Many of the standard c library (fwrite, memset, malloc) functions have direct equivalents in
I have a windows application running at the backend. I have functions in this
We have scalar functions in our database for returning things like number of tasks
I have several functions that I wrote and I use regularly on my servers,

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.