You need to sign in to do that
Don't have an account?

Unable to catch exception
HI,
I have written a controller, and a page that uses it. This method catches an exception, I am trying to pass the error to the apex : messages visualforce page .
Clicking Running this method, I get an "An unexpected error has occurred. " page. what's wrong with my exception catching?
public void deleteOldInvoices() {
//this method is in the controller. it is run from the page try { //some code here. } } catch (Exception e) { Apexpages.addMessages(e); } }
Thanks
Ben
Ben,
It's causing an error because the addMessages method is expecting a ApexPages.Message as the parameter instead of an Exception. The code below should work.
try { //some code here. } catch (Exception e) { ApexPages.addMessage(new ApexPages.Message( ApexPages.severity.ERROR, e.getMessage()) ); }
Thanks Jessie.
I've just solved it, apparently the exception was coming from the constructor....
Actually, what you say is not quite precise.
ApexPages.Message only accepts a message, but ApexPages.Messages actually accepts an Exception object. it works fine for me...
Thanks.
Ben