[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Object reference not set to an instance of an object. in Catch of exception

Posted on 2007-10-19
2
Medium Priority
?
1,309 Views
Last Modified: 2012-06-21
I'm getting a null exception error.  We started to build out our data layer using enterprise library.  I can't get with one of my team members to figure out if our exception handling block is all set to go yet.  But even if I take out the if statement below for the exception, it still gives me this error:

this is part of a try catch for one of my methods in the DAL class I'm working with:

                    catch (Exception ex)
                    {
                        if (ExceptionPolicy.HandleException(ex, "MyCompany.TY.DataLayer.RR.Exceptions"))
                        {
                            throw;
                        }
                    }

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 2018:                    catch (Exception ex)
Line 2019:                    {
Line 2020:                        throw;
Line 2021:                    }
Line 2022:                }


Source File: C:\www\prototype\MyCompany.TY.DataLayer\Databases\RR\Student.generated.cs    Line: 2020

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.GetExceptionPolicyData(String policyName) +51
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +99
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +72
   Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +171
   Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +88
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +310
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +71
   Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) +75
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IReadWriteLocator locator, String id, IConfigurationSource configurationSource) +144
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name) +56
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory) +33

[ExceptionHandlingException: Object reference not set to an instance of an object.]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory) +178
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) +45
   MyCompany.MyCompany.DataLayer.KCC.Student.GetStudent_TestTransactionScopeID(Int32 iStudentID) in C:\www\prototype\MyCompany.TY.DataLayer\Databases\RR\Lead.generated.cs:2020
   MyCompany.MyCompany.BusinessLayer.KStudent.GetStudent_TestTransactionScopeID(Int32 studentId) in C:\www\prototype\MyCompany.TY.BusinessLayer\Lead.cs:34
   MyCompany.MyCompany.WebLayer.BusinessConsumer.TransactionScopeTesting.Page_Load(Object sender, EventArgs e) in C:\www\prototype\MyCompany.MyCompany.WebLayer.BusinessConsumer\TestTransactionScope.aspx.cs:21
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
0
Comment
Question by:dba123
2 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20113516
try to use
throw new Exception()
0
 
LVL 14

Accepted Solution

by:
Jai S earned 1000 total points
ID: 20113569
you have to say what you want to THROW...what kind of exception...
either you can throw the same exception(ofcourse it does not make any sense"

but the funny thing WHY do you really want to THROW an exception inside a CATCH...you have to find ways to eliminate it
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question