我使用的Spring.net + Nhibernate +mvc有这么一段配置
<databaseSettings>
<add key="db.datasource" value="aaaaa" />
<add key="db.user" value="sa" />
<add key="db.password" value="1111" />
<add key="db.database" value="bbbbb" />
</databaseSettings>
我故意配置错误,
然后在action里面调用
try{
var iof = Spring.Context.Support.ContextRegistry.GetContext(); return iof.GetObject("SessionService") as ISessionService;
}
catch{}
就是捕捉不到异常,但是确实有异常为System.Configuration.ConfigurationErrorsException,
异常出在这句话 var iof = Spring.Context.Support.ContextRegistry.GetContext();vs提示说没有处理异常,
为什么没有将异常传递到catch里
<databaseSettings>
<add key="db.datasource" value="aaaaa" />
<add key="db.user" value="sa" />
<add key="db.password" value="1111" />
<add key="db.database" value="bbbbb" />
</databaseSettings>
我故意配置错误,
然后在action里面调用
try{
var iof = Spring.Context.Support.ContextRegistry.GetContext(); return iof.GetObject("SessionService") as ISessionService;
}
catch{}
就是捕捉不到异常,但是确实有异常为System.Configuration.ConfigurationErrorsException,
异常出在这句话 var iof = Spring.Context.Support.ContextRegistry.GetContext();vs提示说没有处理异常,
为什么没有将异常传递到catch里
<!--SpringCfgStrat-->
<!--ConfigSections-->
<configSections>
<section name="databaseSettings" type="System.Configuration.NameValueSectionHandler" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
</sectionGroup>
</configSections>
<!--String to connect special db-->
<databaseSettings>
<add key="db.datasource" value="aaaaa" />
<add key="db.user" value=" sa" />
<add key="db.password" value="1111" />
<add key="db.database" value="bbbbb" />
</databaseSettings>
<!--Ref XML-->
<spring>
<context>
<resource uri="assembly://NetDiskRepository/NetDiskRepository/NhibernateCfg.xml" />
<resource uri="assembly://NetDiskRepository/NetDiskRepository/RepositoryCfg.xml" />
<resource uri="assembly://NetDiskService/NetDiskService/TransactionCfg.xml" />
<resource uri="assembly://NetDiskService/NetDiskService/ServiceBeanCfg.xml" />
</context>
</spring>
<!--SpringCfgEnd-->
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>