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
Vandana M 14Vandana M 14 

Can anyone share how to catch the error in Visualforce Page?

Meghna Vijay 7Meghna Vijay 7
Hi Vandana,

1) Use apex:messages tag in Visualforce Page
2) Use Try catch block in Visualforce Controller and use ApexPageMessages.addMessage (Exception) in the catch block.

Hope it helps, if it does mark it as solved.

Thanks
Deepali KulshresthaDeepali Kulshrestha
Hi Vandana,
Greetings to you!
    
- I read your problem and implemented in my Org.
- Please use the below code [Solved] : -

     try{
     // Your code here
     } catch(Exception ex){
        Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL, 'No such combination exists'));
     }
    
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Ajay K DubediAjay K Dubedi
Hi Vandana,
You can use <apex:pageMessages> for Error Handling in Visualforce.

Here is the link for that:
http://www.interactiveties.com/blog/2015/visualforce-apex-pagemessages.php
http://www.sfdcpoint.com/salesforce/apexpagemessage-and-apexpagemessages-salesforce/
And here is the same problem as your's:
https://salesforce.stackexchange.com/questions/191078/displaying-an-error-message-on-a-visualforce-page?rq=1
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi