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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Not all paths return value with try and catch

(0) ShareShare
ReportReport
Posted on by 1,552

Hi ,

what should i do? i tried putting return null inside the big catch but it didn't work.

    public str fcn()
    {
        System.Net.WebException webEx;
        System.Net.WebException webExInner;
        System.Exception        ex;
        System.Exception        exInner;
        try
        {   

            //logic 

            str webResponse = this.test();
            return webResponse;
        }
        
        catch(webEx)
        {
            try
            {
                System.Net.HttpWebResponse  webResponse = webEx.Response;
                     
                switch (webResponse.StatusCode)
                {
                    case 409:
                        if(//logic)
                        {
                            //logic
                        }
                        else
                        {
                             error("@label"    " "   webEx.get_Message()); 
                        }
                        break;
                    default:
                             error("@label"   " "   webEx.get_Message());

                }
            }
            catch (webExInner)
            {
                error("label"   " "   webExInner.get_Message());
            }

            catch(exInner)
            {
                error("label"   " "   exInner.get_Message());
            }
            
        }

        catch (Exception::Error)
        {
            
        }

        catch(ex)
        {
            error("@label"   " "   ex.Message);
        }

        finally
        {
            //logic
        }
        
    }

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi juniorAX,

    Try returning at the end of the method. Please try this code and check if that works -

    public str fcn()
    {
    	System.Net.WebException webEx;
    	System.Net.WebException webExInner;
    	System.Exception        ex;
    	System.Exception        exInner;
    	str 					webResponse;
    	try
    	{   
    		//logic 
    		webResponse = this.test();		
    	}
    	
    	catch(webEx)
    	{
    		try
    		{
    			System.Net.HttpWebResponse  webResponse = webEx.Response;
    				 
    			switch (webResponse.StatusCode)
    			{
    				case 409:
    					if(//logic)
    					{
    						//logic
    					}
    					else
    					{
    						 error("@label"    " "   webEx.get_Message()); 
    					}
    					break;
    				default:
    						 error("@label"   " "   webEx.get_Message());
    
    			}
    		}
    		catch (webExInner)
    		{
    			error("label"   " "   webExInner.get_Message());
    		}
    
    		catch(exInner)
    		{
    			error("label"   " "   exInner.get_Message());
    		}
    		
    	}
    
    	catch (Exception::Error)
    	{
    		
    	}
    
    	catch(ex)
    	{
    		error("@label"   " "   ex.Message);
    	}
    
    	finally
    	{
    		//logic
    	}
    	
    	return webResponse;
    }

  • junior AX Profile Picture
    1,552 on at

    Thanks alot Gunjan

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans