Apex BOOST Library
v1.7 from Lucidware Solutions (LWS)

AssertException

global inherited sharing class AssertException extends Exception
Description

This exception is thrown by the Assert methods. Unlike System.AssertException, AssertException can be caught by custom code. This makes it possible for you to use Assert within your code and write unit tests that test those assertions.

Usage:
 // validate a parameter using an assertion
 public with sharing class MyClass {
   public MyClass(Id imporantId) {
     aBoost.Assert.areNotEqual(null, importantId, 'an importantId is required!');
     ...
   }
 }

 // test parameter validation on the MyClass constructor
 @IsTest class MyClassTest {
   @IsTest static void testConstructor() {
     Test.startTest();
       try {
         new MyClass(null);
         System.assert(false, 'a missing importantId should fail');
       } catch (aBoost.AssertException expected) {}
     Test.stopTest();
   }
 }