web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

catch exception x++

(1) ShareShare
ReportReport
Posted on by 190
Hi,

I know that catch(ex) is good as it catches mostly everything, but in my code here i don't use it
do i need it?
how to make my code better?
 
 public ResponseContract createCustomer(RequestContract _requestContract)
 {
     int startLine = Global::infologLine();
    ResponseContract  responseContract  = new ResponseContract ();
     System.Exception    ex;

     try
     {
        //logic
     }
     catch(ex)
     {
        int     currentLine;
        str     errorMessage;
        boolean ret = true;

        for (currentLine = _startLine + 1; currentLine <= infologLine(); currentLine++)
        {
            if (ret)
            {
                errorMessage = infolog.text(currentLine);
                ret = false;
            }
            else
            {
               errorMessage += '\n' + infolog.text(currentLine);
            }
        }

         response.parmMessage(errorMessage);
         
     }

     return responseContract;
 }
 
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,533 Most Valuable Professional on at
    Whether you need to handle exceptions in a special way or you can just use the default handler depends on your business requirements.
     
    Your code populating errorMessage variable is indeed useless, because the variable isn't used for anything.
     
    But it's not the same as if you didn't use any catch clause at all. Your code is an equivalent of an empty catch clause - it swallows the exception without doing anything with it.
  • Subra Profile Picture
    582 on at
    Hi 

    Always catch is good to have in your code and keep it with default catch execption. if you don't need it for your business requirements.
  • Martin Dráb Profile Picture
    239,533 Most Valuable Professional on at
    Always catching exceptions is a bad idea. If you aren't interested in handling an exception and you catch it without rethrowing, you've just created a critical bug. The application will continue to run in a fault state instead of throwing an exception, which may have huge consequences.
    Even if you rethrow the exception, it's much worse than not catching it at all. The behavior will be the same, but performance will be worse and debugging more complicated.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 661 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 620

#3
Subra Profile Picture

Subra 473

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans