473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

try/catch compilation warning

Hello:

I notice that the following statements generate a "the variable 'e' is
declared but never used" warning:

try
{
Company.Fetch(CompanyID);
}
catch(RecordNotFoundException e)
{
return null;
}

I have no reason to use the variable e within my catch block and find this
warning annoying (my code is generating many such warnings). Is there a
commonly used way to avoid a compilation warning in this situation?

Thanks,
Chris
Nov 16 '05 #1
7 3469
catch(RecordNotFoundException)

ChrisB wrote:
Hello:

I notice that the following statements generate a "the variable 'e' is
declared but never used" warning:

try
{
Company.Fetch(CompanyID);
}
catch(RecordNotFoundException e)
{
return null;
}

I have no reason to use the variable e within my catch block and find this
warning annoying (my code is generating many such warnings). Is there a
commonly used way to avoid a compilation warning in this situation?

Thanks,
Chris

Nov 16 '05 #2
Hi ChrisB,

Sure is, change your catch block to

catch
{
return null;
}

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
ChrisB wrote:
[...]
I have no reason to use the variable e within my catch block and find this
warning annoying (my code is generating many such warnings). Is there a
commonly used way to avoid a compilation warning in this situation?


In that case, use the following to simply filter the exception.

try
{
Company.Fetch(CompanyID);
}
catch(RecordNotFoundException)
{
return null;
}
Nov 16 '05 #4
ChrisB <pl****************@thanks.com> wrote:
I notice that the following statements generate a "the variable 'e' is
declared but never used" warning:

try
{
Company.Fetch(CompanyID);
}
catch(RecordNotFoundException e)
{
return null;
}

I have no reason to use the variable e within my catch block and find this
warning annoying (my code is generating many such warnings). Is there a
commonly used way to avoid a compilation warning in this situation?


Yes - don't declare the variable:

catch (RecordNotFoundException)
{
return null;
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Morten Wennevik <Mo************@hotmail.com> wrote:
Sure is, change your catch block to

catch
{
return null;
}


That then catches *all* exceptions, however, which may very well not be
what is wanted.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Simple enough. Thanks!

"C# Learner" <cs****@learner.here> wrote in message
news:Ou*************@TK2MSFTNGP10.phx.gbl...
ChrisB wrote:
[...]
I have no reason to use the variable e within my catch block and find this warning annoying (my code is generating many such warnings). Is there a
commonly used way to avoid a compilation warning in this situation?


In that case, use the following to simply filter the exception.

try
{
Company.Fetch(CompanyID);
}
catch(RecordNotFoundException)
{
return null;
}

Nov 16 '05 #7
Good point

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ced | last post by:
Hi, i'm not an expert in C but i try to compile BTNG software under linux kernel 2.4.2-2. I get these errors at the very first stage. Does someone could have a rapid look on this and tell me...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
6
by: alban | last post by:
Hello I have got some problems of compilation on a AIX IBM, I use the XLC compilator (And I can't install another one). I try to compile code Pro*c ".pc" (oracle), I need do a pre-compilation...
6
by: subramanian | last post by:
Consider the following program: #include <stdio.h> void myfn(const int **a) { static int i, j, k; a = &i; a = &j;
1
by: hamardk | last post by:
Hi, I'm trying to compile log4cpp-0.3.5rc3 on : SunOS belaurora 5.9 Generic_118558-11 sun4u sparc SUNW,Ultra-4 I'm having compilation issues which are: In file included from...
7
by: antoine | last post by:
Hi all! I'm a French student currently doing an internship in Beijing. I have to simulate a mips machine running with the micro kernel l4. When i compile the kernel i got some compilation errors. I...
3
by: Richard Weeks | last post by:
My question, stated as simply as possible, is: must a constraint violation, as defined by the standard, cause compilation to halt? I believe that in the presence of a constraint violation, at...
4
by: | last post by:
Hi, After installing SP1 for VS2008 and SP1 for .NET 3.5 we get the following warning in a VS2005 build: error CS0618: Warning as Error: 'System.Windows.UIElement.BitmapEffect' is obsolete:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.