Is there a way to catch System.AssertException?
For example, some class is known to throw assertions in certain cases and it's ok to deal with that on some upper level. But unfortunately straightforward try-catch doesn't work for assert. I expect that this code will not throw an exception but it does:
try{
System.assert(false, 'fail');
}catch(System.AssertException asEx){
System.debug('success');
}
So, is there a way to implement ability of catching asserts?
Best Answer
Short answer no.
From the Apex Developers Guide:
You'll need to convert your asserts to exceptions if you want to handle them either at the point that they are thrown, or in any calling code.