Created
November 9, 2012 22:30
-
-
Save ralphcallaway/4048738 to your computer and use it in GitHub Desktop.
Example of good exception handling for vf pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void functionWithDML() { | |
try { | |
insert listOfStuff; | |
} catch(DMLException e1) { | |
// do nothing here, page messages are automatically generated | |
} catch(Exception e2) { | |
// uh-oh, something else happened bad, better show it to the user | |
ApexPages.addMessage( | |
new ApexPages.Message( | |
ApexPages.Severity.ERROR | |
, 'Unknown exception while inserting your list of stuff. Please contact support. Exception: ' + e | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment