FAQ

[Lucene.Net] [jira] [Created] (LUCENENET-439) Correctly Rethrow exceptions in C#

michael herndon (JIRA)
Jul 22, 2011 at 6:11 pm
Correctly Rethrow exceptions in C#
----------------------------------

Key: LUCENENET-439
URL: https://issues.apache.org/jira/browse/LUCENENET-439
Project: Lucene.Net
Issue Type: Sub-task
Components: Lucene.Net Core, Lucene.Net Test
Affects Versions: Lucene.Net 2.9.2, Lucene.Net 2.9.4, Lucene.Net 2.9.4g
Environment: all
Reporter: michael herndon


There are a few places in the tests and possibly in the code where exceptions are being rethrown incorrectly and erasing stacktrace.

Please fix these as you come across them and add the ticket number in the commit message.

BaseTokenStreamTestCase.cs has a good example of this. Inside the RunBare method:

// Do the test again with onlyUseNewAPI=true
try
{
onlyUseNewAPI = true;
base.RunBare();
}
catch(Exception ex)
{
System.Console.Out.WriteLine("Test failure of '" + GetType() + "' occurred with onlyUseNewAPI=true");
throw ex;
}

in this case you don't need to specify the exception, and we're trapping to write out the context of the exception problem.

try
{
onlyUseNewAPI = true;
base.RunBare();
}
catch
{
Type type = this.GetType();
Console.WriteLine("Test failure of '" + type.Name + "' occurred with onlyUseNewAPI=true");
throw;
}

http://msdn.microsoft.com/en-us/library/ms182363(v=vs.80).aspx
http://winterdom.com/2002/09/rethrowingexceptionsinc

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
reply

Search Discussions

2 responses

  • Christopher Currens (Updated) (JIRA) at Jan 24, 2012 at 5:14 am
    [ https://issues.apache.org/jira/browse/LUCENENET-439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

    Christopher Currens updated LUCENENET-439:
    ------------------------------------------

    Fix Version/s: Lucene.Net 3.0.3
    Correctly Rethrow exceptions in C#
    ----------------------------------

    Key: LUCENENET-439
    URL: https://issues.apache.org/jira/browse/LUCENENET-439
    Project: Lucene.Net
    Issue Type: Sub-task
    Components: Lucene.Net Core, Lucene.Net Test
    Affects Versions: Lucene.Net 2.9.2, Lucene.Net 2.9.4, Lucene.Net 2.9.4g
    Environment: all
    Reporter: michael herndon
    Labels: refactoring, testing,
    Fix For: Lucene.Net 3.0.3


    There are a few places in the tests and possibly in the code where exceptions are being rethrown incorrectly and erasing stacktrace.
    Please fix these as you come across them and add the ticket number in the commit message.
    BaseTokenStreamTestCase.cs has a good example of this. Inside the RunBare method:
    // Do the test again with onlyUseNewAPI=true
    try
    {
    onlyUseNewAPI = true;
    base.RunBare();
    }
    catch(Exception ex)
    {
    System.Console.Out.WriteLine("Test failure of '" + GetType() + "' occurred with onlyUseNewAPI=true");
    throw ex;
    }
    in this case you don't need to specify the exception, and we're trapping to write out the context of the exception problem.
    try
    {
    onlyUseNewAPI = true;
    base.RunBare();
    }
    catch
    {
    Type type = this.GetType();
    Console.WriteLine("Test failure of '" + type.Name + "' occurred with onlyUseNewAPI=true");
    throw;
    }
    http://msdn.microsoft.com/en-us/library/ms182363(v=vs.80).aspx
    http://winterdom.com/2002/09/rethrowingexceptionsinc
    --
    This message is automatically generated by JIRA.
    If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
    For more information on JIRA, see: http://www.atlassian.com/software/jira
  • Christopher Currens (JIRA) at Jun 22, 2012 at 9:56 pm
    [ https://issues.apache.org/jira/browse/LUCENENET-439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

    Christopher Currens updated LUCENENET-439:
    ------------------------------------------

    Fix Version/s: (was: Lucene.Net 3.0.3)
    Lucene.Net 3.5
    Correctly Rethrow exceptions in C#
    ----------------------------------

    Key: LUCENENET-439
    URL: https://issues.apache.org/jira/browse/LUCENENET-439
    Project: Lucene.Net
    Issue Type: Sub-task
    Components: Lucene.Net Core, Lucene.Net Test
    Affects Versions: Lucene.Net 2.9.2, Lucene.Net 2.9.4, Lucene.Net 2.9.4g
    Environment: all
    Reporter: michael herndon
    Labels: refactoring, testing,
    Fix For: Lucene.Net 3.5


    There are a few places in the tests and possibly in the code where exceptions are being rethrown incorrectly and erasing stacktrace.
    Please fix these as you come across them and add the ticket number in the commit message.
    BaseTokenStreamTestCase.cs has a good example of this. Inside the RunBare method:
    // Do the test again with onlyUseNewAPI=true
    try
    {
    onlyUseNewAPI = true;
    base.RunBare();
    }
    catch(Exception ex)
    {
    System.Console.Out.WriteLine("Test failure of '" + GetType() + "' occurred with onlyUseNewAPI=true");
    throw ex;
    }
    in this case you don't need to specify the exception, and we're trapping to write out the context of the exception problem.
    try
    {
    onlyUseNewAPI = true;
    base.RunBare();
    }
    catch
    {
    Type type = this.GetType();
    Console.WriteLine("Test failure of '" + type.Name + "' occurred with onlyUseNewAPI=true");
    throw;
    }
    http://msdn.microsoft.com/en-us/library/ms182363(v=vs.80).aspx
    http://winterdom.com/2002/09/rethrowingexceptionsinc
    --
    This message is automatically generated by JIRA.
    If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
    For more information on JIRA, see: http://www.atlassian.com/software/jira

Related Discussions

Discussion Navigation
viewthread | post

1 user in discussion

Christopher Currens (JIRA): 3 posts