2

I'm developing an error handling platform for apex but I'm facing some doubts. Is there a way catch the unhandled exceptions? When using a public site page, the user is redirected to an error page that I can override but how can I control it when using an internal page? And how can I see or catch the Exception that took me to that page?

Pedro.

2
  • putting a Debug Log on the Site Guest User will usually reveal the exception Commented Apr 18, 2013 at 10:44
  • 1
    Yes, but I want to send that exception to an error handling tool Commented Apr 18, 2013 at 10:54

1 Answer 1

1

If I understand your question correctly and you are developing some Apex behind a public site page. You can utilise the try...catch aspect of Apex to catch errors raised from your code or triggers your code invokes. Please take a look at this topic in the Apex Developers Guide.

try {
 code_block
} catch (exceptionType) {
 code_block
}
// Optional catch statements for other exception types.
// Note that the general exception type, 'Exception',
// must be the last catch block when it is used.
} catch (Exception e) {
 code_block
}
// Optional finally statement
} finally {
 code_block
}
4
  • 1
    Thanks for your answer. I'm developing apex behind a public site page and behind as an usual visualforce page tu use in backoffice. What you're saying is the common try/catch statement to catch the errors that we predict. But, as you may know, there's always errors that we didn't predict. There's a way to catch that exceptions? Or some way to know what made the exception from that error page to notify my error handling? Commented Apr 18, 2013 at 10:37
  • 4
    Unhandled exceptions results from not catching exceptions using try catch. The only sort of exceptions which you cant catch are for eg Limit Exceptions, which the platform doesnt intend for you to handle. Commented Apr 18, 2013 at 10:42
  • That's correct. But I want some kind of general exception handler to notify the error handling tool that an exception has occurred. In other terms, in the case of public pages, I want to know what was the exception that took the user to the error page. Is there any way to know that exception from that page? And, is there an error page for non-public pages? Commented Apr 18, 2013 at 10:48
  • Pedro, if you've not read it already, you might want to take a look at Advanced Apex Programming by Dan Appleman. He illustrates how to implement the kind of exception handling strategy that you're working on. There may be some tips in there which you'll find helpful to you. Off hand, the only way I know of would be to have a long list of different types of possible exceptions in your try catch blocks (null pointer, list exception, string exc, etc). When that type is caught, it then gets written to a custom field, the results of which are displayed on the error pages.
    – crmprogdev
    Commented Apr 18, 2013 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .