axaptadynamics-ax-2012x++dynamics-ax-2012-r2dynamics-ax-2012-r3

handle exception in try catch block


I have a switch case scenario where I know beforehand that there is a high level of opportunity that the user might not set the the rules with the right categories. it's totally ok for me as soon as i can pop up a dialog showing instructions what to do in order to run the program. However i am missing something and here is my question.

When i test a scenario as per above the cursor goes through the default case, and pops up the error. How can i make it goes into my catch block?

try  
{
    switch (userInput)
    {
        case 1:
        case 2:
        case 3:
            if (condition)
            {
               some code here
            }
            else
            {
                throw error();
            }
            break;
        case 4:
            postingType = smth;
            break;
        default:
            throw Global::error("here blows the error and does not move on to the catch");
    }
}
catch(exception::Error)
{
    info("test");
}

Your help is much appreciated!

Thank you in advance and have a nice evening.

H.


Solution

  • The reason is that exceptions generally aren't caught inside database transactions. I explained it with a little more details in the thread about the same question in the Dynamics community forum, where it's been marked as the verified answer.