== Why is this an issue?

``++throw(NULL)++`` is equivalent to ``++throw(0)++``, and is therefore caught by an integer handler. However, since ``++NULL++`` is typically used in the context of pointers, developers may expect it to be caught by a pointer-to-type handler. Thus to avoid confusion, zero should be thrown instead of ``++NULL++``.


=== Noncompliant code example

[source,cpp]
----
try
{
  throw ( NULL ); // Noncompliant
}
catch ( int32_t i ) // NULL exception handled here
{
  // ...
}
catch ( const char_t * ) // Developer may expect it to be caught here
{
  // ...
}
----


=== Compliant solution

[source,cpp]
----
try
{
  throw ( 0 );
}
catch ( int32_t i )
{
  // ...
}
catch ( const char_t * )
{
  // ...
}
----


== Resources

* MISRA {cpp}:2008, 15-1-2


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

=== on 16 Aug 2016, 18:06:27 Alban Auzeill wrote:
I close this rule in favor of [RSPEC-3696] that mark as non-compliant NULL and 0 (zero).

=== on 16 Aug 2016, 19:28:50 Ann Campbell wrote:
As an addendum to the previous comment: ``++NULL++`` evaluates to 0, so we can't distinguish between ``++throw NULL++`` and ``++throw 0++``.

endif::env-github,rspecator-view[]
