Why isn't my X++ catch block catching an exception?
Why isn't my X++ catch block catching an exception?
1 answer
Write an answerThe 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.
Know the solution?
Sign in to contribute an answer and build your community reputation.
Sign in to answer