dbTalk Databases Forums  

Error hanlding in Stored procedure or .Net Application

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss Error hanlding in Stored procedure or .Net Application in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rogers
 
Posts: n/a

Default Error hanlding in Stored procedure or .Net Application - 07-04-2008 , 10:01 PM






Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #2  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM






For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #3  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #4  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #5  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #6  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #7  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #8  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #9  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
  #10  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Error hanlding in Stored procedure or .Net Application - 07-06-2008 , 10:06 PM



For some, this can be a quite emotional topic. But in general, the software
engineering principles apply here. That is, you want to maintain modular
code, you want to keep encapsulation, and you want to ensure tight cohesion
inside a module and loose coupling between modules. So the key argument
against handling all the errors in the application code (.NET C# code for
instance) is that it destroys encapsulation, and makes the error handling
logic unnecessarily complex in the app when it can be simpler if certain
errors are handled inside T-SQL. Especially, for some proc errors, if all
that the app should do is to just resubmit the proc, handling the errors in
the proc can save you some network trips.

But on the other hand, you can't really dictate that all the errors should
be handle inside T-SQL. First of all, the T-SQL TRY/CATCH mechanism is not
designed to catch all the errors. So it can't all be done all inside T-SQL.
Secondly, if the logical action of a proc error is to do something else
beyond that proc, it's probably better to let the app control the logic.

So unfortunately there is no simple answer, although there are some general
rules of thumb (such as you want to contain the error handling to the
smallest scope) as the derivatives of general software engineering
principles. You really have to examine each error condition on a case by case
basis.

Linchi

"Rogers" wrote:

Quote:
Dear Professional,

I had serious debate in my organization and I told to my developers to use
Error Handling in Stored procedure BEGIN TRY END TRY BEGIN CATCH END CATCH
but they are saying error handling is better in .Net code instead of stored
procedure,

Please advice me which way is better and give me any solid reason so that I
can explain them very easily.

Your help is really appreciated

Thanks in advance.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.