try/catch 내부에서 사용하거나 try/catch 내부에서 사용하는 올바른 방법은 무엇입니까? 내 관점에서sqlConnection/명령문 + try/catch 블록을 사용하는 명령
using (SqlConnection connection = CreateSqlConnection(connString))
{
using (SqlCommand command = CreateSqlCommand()
{
try{//open connection + execute command + do something else}
catch{//do something}
}
}
대
try
{
using (SqlConnection connection = CreateSqlConnection(connString))
{
using (SqlCommand command = CreateSqlCommand()
{
//open connection + execute command + do something else
}
}
}
catch
{
//do something
}
을 원하는대로 예외를 처리 할 수 있지만, 사용 한 Statment 자체가 의문이다, 그것을 행동을 나던 try, catch 및 finally 함수와 유사합니까? 그렇다면 사용 기능을 랩 할 필요가 있습니까? – lemunk
그러나 이것은 반대하지 않습니다.'try {using (...) {try {}}}'. 또한, ** 연결 문을 **에서'using' 문과 외부가 아닌 다른 곳에서 여는 것이므로,'Try-Catch'를 사용하여 그 자체를 사용하는 것이 왜 다른 범위입니까? 나쁜 것을 너무 많이 잡을 위험에 처해 있습니다. –
하지만 내 관점에서 위의 하나에서 선택의 incase 두 번째는 더 낫다. –