Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:47:11+00:00 2026-06-06T05:47:11+00:00

I am having a function as follows: public int CreateMyTask() { Console.WriteLine(Invoking CreateTask method);

  • 0

I am having a function as follows:

public int CreateMyTask()
{
    Console.WriteLine("Invoking CreateTask method");
    Console.WriteLine("-----------------------------------");
    m_taskID = taskClient.CreateTask(m_tInstance);
    Console.WriteLine("Task create successfully:ID=" + m_taskID.ToString());
    Console.WriteLine("-----------------------------------");
    return m_taskID;
}

What I need to do is :-

  1. I must check the function whether an exception has occurred. Any exception can occur basically. We are not bothered about what exception has occurred. We simple need to find whether AN exception HAS occurred or not. Let that exception be anything.

  2. If an exception has indeed occurred, I must record a word “FAIL” in row 2, cell 10 of my excel sheet (D:\excel.xls) and add the text related to the exception like “Nullreference exception has occurred” or “divide by zero exception has occurred” or any exception that has occurred. The exact text of the exception must be copied to row 2, cell 11

  3. If no exception has occurred, then I must record a word “PASS” in row 2, cell 10 of my excel sheet.

Can someone help me to get started on this ? Am quite new to c#. Could so with some inputs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:47:12+00:00Added an answer on June 6, 2026 at 5:47 am
    public int CreateMyTask()
    {
            try
            {
                Console.WriteLine("Invoking CreateTask method");
                Console.WriteLine("-----------------------------------");
                m_taskID = taskClient.CreateTask(m_tInstance);
                Console.WriteLine("Task create successfully:ID=" + m_taskID.ToString());
                Console.WriteLine("-----------------------------------");
                WriteResultInExcel(false, "");
                return m_taskID;
            }
            catch(Exception ex)
            {
                WriteResultInExcel(true, ex.Message);
            }
    }
    
    
     private void WriteResultInExcel(bool isExceptionalData, string message)
     {
            Excel.ApplicationClass excelApp = new ApplicationClass();
            Workbook workbook = excelApp.Workbooks.Open("D:\\excel.xls", 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            Worksheet worksheet = (Worksheet)workbook.Sheets.get_Item(1);
            if(isExceptionalData)
            {
                ((Range)worksheet.Cells["2", "J"]).Value2 = "FAIL";
                ((Range)worksheet.Cells["2", "K"]).Value2 = message;
            }
            else
            {
                ((Range)worksheet.Cells["2", "J"]).Value2 = "PASS";
            }
            workbook.Save();
            workbook.Close(0, 0, 0);
            excelApp.Quit();
     }
    

    Make sure to check the existence of your file “D:\excel.xls” and also add the reference to “Microsoft.Office.Interop.Excel”.

    Don’t miss to add this to your directives section:

    using Microsoft.Office.Interop.Excel;
    using Excel = Microsoft.Office.Interop.Excel;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this trivial function: public static bool IsPositive(IComparable<int> value) { return value.CompareTo(0) > 0;
I am having following function public static Date parseDate(String date, String format) throws ParseException
Im having this function to determine weather a user exists in a database or
I'm having a function which receives string parameters and convert them to integers. For
I often hear around here from test driven development people that having a function
Is it possible to get the 'nth' return value from a function without having
Having a little difficulty getting a function to call after a .load: $(function(){ $('a.pageFetcher').click(function(){
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
Im having some trouble writing a getstring function, this is what I have so
I'm having a problem with my function. The purpose of my function is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.