+ Start a Discussion
jeremyyjeremyy 

The mysterious System.UnexpectedException

Anyone have any info (documentation, etc.) on System.UnexpectedException?

 

The apex compiler allows it to be used in a catch block, but it doesn't seem to be catchable at runtime. Any info is appreciated.

 

Jeremy

 

sfdcfoxsfdcfox

From my observations, System.UnexpectedException is treated like a governor runtime exception. It can not be constructed, nor can it be caught. This exception occurs when there is an error at the platform level (a bug in the system code that typically has a hot-fix issued for it as soon as the developers can resolve it). While other governor exceptions are documented, because they are caused by particular measurable conditions (i.e. exceeding script limits, heap limits, etc), this class of exception represents an exception that should never happen. When it does happen, your code must cease to execute because that transaction is in an unknown/unstable state that could cause undesirable behavior later in the script. It is the rough equivalent of a desktop application's "General Protection Fault" message-- it is ultimately fatal to the application, as the OS terminates the program before it can do itself or the platform harm.