(XC32) What are various exceptions in PIC32 MCUs and how should they be handled??

In PIC32 MCUs, exceptions can be classified as:

Bootstrap Exception

A Bootstrap exception is an exception which occurs while bootstrap code is running (StatusBEV=1). All Bootstrap exceptions are vectored to 0xBFC00380. At this location, the XC32 Compiler places a branch instruction targeting the function named ‘_bootstrap_exception_handler()’.

General Exception

A general exception is any non-interrupt exception that occurs during program execution outside of bootstrap code (StatusBEV=0). General exceptions are vectored to offset 0x180 from EBase. At this location, the XC32 Compiler places a branch instruction targeting the function named ‘_general_exception_context()’. The provided implementation of this function saves context, calls an application handler function, restores context and performs a return from the exception instruction.

If the user application provides an implementation of ‘_general_exception_context()’, that implementation will be used instead. Prototype of the general exception handler:

Simple Translation Look-aside Buffer (TLB) Refill Exception

During an instruction fetch or data access, a TLB refill exception occurs when no TLB entry matches a reference to a mapped address space and the EXL bit in the Status register is 0. Note that this is distinct from the case in which an entry matches, but has the valid bit off. In that case, a TLB Invalid exception occurs. Prototype of the TLB refill exception handler:

Cache Error Exception

A cache-error exception occurs when an instruction or data reference detects a cache tag or data error. This exception is non maskable. To avoid disturbing the error in the cache array, the exception vector is assigned to an unmapped, uncached address.

For every exception, a weak default implementation exception handler is provided, which causes a Software Reset.
When compiling for in-circuit debugging or emulation, the default implementation of exception handler will first cause a software breakpoint and then cause a software reset (When available on target device).

Example for handling a general exception:

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.