Skip to content

Instantly share code, notes, and snippets.

@ralphcallaway
Created November 9, 2012 22:30
Show Gist options
  • Save ralphcallaway/4048738 to your computer and use it in GitHub Desktop.
Save ralphcallaway/4048738 to your computer and use it in GitHub Desktop.
Example of good exception handling for vf pages
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