General X++ Development

Why isn't my X++ catch block catching an exception?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

Why isn't my X++ catch block catching an exception?

SSunny Vasty75 reputation · answered Aug 13, 2026

The first thing I check is transaction scope and exception type.

Most exceptions thrown inside a ttsBegin/ttsCommit transaction cannot be caught by a normal catch that is still inside that same transaction scope. The exception unwinds the transaction first.

UpdateConflict and DuplicateKeyException have special handling and can be caught explicitly inside transaction scope.

Also make sure you are catching the right kind of exception. A CLR exception will not behave the same way as a normal Exception::Error.

If the catch "should work" but does not, move the try/catch outside the transaction and verify the exact exception being thrown.