function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nikhil BanaitNikhil Banait 

Why Force.com sites redirects to “Authorization Required” page when any Apex Exceptions occurs?

Why Force.com sites redirects to “Authorization Required” page when any Apex Exceptions occurs?
“Unauthorized” page makes sense in case of missing access problem.
But in case of Exceptions ideally the redirect should be the “Exception” page.

I want my site redirect to 'Generic Error Page' i.e. Exception page when any Apex Exceptions occurs. 
How can I achieve this?
Any help will be appreciated.
Phillip SouthernPhillip Southern
Do a try catch to capture all exceptions in your controller...once you catch htem you can push up to the page and display as needed.
Nikhil BanaitNikhil Banait
Thank you for your help.

How can I implement your answer in apex code?
In catch block, how to redirect to the  'Generic Error Page' i.e. Exception page?
CheyneCheyne
You can do something like this (if your 500 page is called ErrorPage):

try {
    //some code that might fail
} catch (Exception e) {
    //this will run if something goes wrong in the try block
    return Page.ErrorPage;
}