मैंने अपने आवेदन में अपवाद को संभालने के इस तरीके का पालन किया है। लेकिन मेरे नेतृत्व ने कहा कि मैं इसे गलत कर रहा हूं। मैं बस एक ही अपवाद को लपेट रहा हूं और फिर से प्रयास कर रहा हूं, जो प्रदर्शन को प्रभावित करेगा।क्या अपवाद प्रभाव प्रदर्शन को लपेटना और पुनर्स्थापित करना है?
मेरे दृष्टिकोण में क्या गलत है? क्या किसी के पास कोई सुझाव है कि मैं यहां अपवाद कैसे लॉग और संभाल सकता हूं?
public class BusinessRepository : IBusinessRepo
{
public List<Employee> GetEmployees()
{
try
{
//do some DB operations
}
catch (SQLException sqlex)
{
Logger.Log("Exception detail with full stack trace");
throw new DALException(sqlex, "Error in data access layer");
}
}
}
public class BusinessLayerClass : IBusinessLayer
{
private readonly IBusinessRepo Repo;
public BusinessLayerClass(IBusinessRepo rep)
{
Repo = rep;
}
public List<Employee> GetEmployees()
{
try
{
List<Employee> emps= return Repo.GetEmployees();
}
catch (DALException dex)
{
//do nothin as it got already logged
throw;
}
catch (Exception ex)
{
Logger.Log(ex, "Business layer ex");
throw new BusinessLayerEx(ex);
}
}
}
public class HomeController : Controller
{
public ActionResult Index()
{
try
{
List <Employee>= BusinessLayerClass.GetEmployees();
}
catch (DALException)
{
//show error msg to user
}
catch (BusinessLayerEx)
{
//show error msg to user
}
catch (Exception ex)
{
Logger.Log();
//show error msg to user
}
return View(emps);
}
}
मैं ऊपर दिखाए गए उत्साह से भरा हुआ और हैंडलिंग और प्रवेश की सही तरीके से पालन करें?
जॉन स्कीट प्रदर्शन के अनुसार अपवाद फेंकने से शायद ही कभी प्रभावित होता है। देखें: http://www.developerfusion.com/article/5250/exceptions-and-performance-in-net/ – albertjan
चूंकि अपवाद असाधारण होना चाहिए, क्या इससे कोई फर्क पड़ता है? – emartel
@albertjan मैं जॉन स्कीट पर सहमत हूं। लेकिन क्या मेरा दृष्टिकोण संभाल और लॉग करने का सही तरीका है? – Billa