Hello,
I'm trying to hop on the n-tier/OOP bandwagon for my applications, but I've hit one snag that I'm not sure the best way to proceed. Say a SqlException is raised in my Data Access layer, that is a long long way from my presentation layer/aspx page, where I would at least like to print out a notification that an error was raised. How can I best achieve this in an n-tier environment. It seems if I handle the error in my Data Access layer, by the time the code execution gets back to the presentation layer, it won't know what happened. Should I be defining my own object exceptions, and raise them when I catch an error, and let it propigate itself up the pipeline until the presentation layer can handle it?
Any help would be greatly appreciated!
--Michael 6 5223
Statement: "It seems if I handle the error in my DAL"
Question: Can you actually handle the error (like, hit a backup database, or
hit a cache which might be stale but will give some information) or can you
just swallow it?
I ask because my guess is that you can't actually handle it at the DAL
layer - all you can do is catch it at the presentation layer and display a
friendly error message. At that point, you have two options:
1 - let the exception bubble up (either don't catch it, or have an empty
throw (don't do a Throw ex))
2 - If, and only if, you can add additional information to the exception,
rethrow a new exception (custom or not) making sure to include the original
exception in there. (throw new ApplicationException("Doh",
originalException))
Karl
"Raterus" <mo*********@suretar.reverse> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
Hello,
I'm trying to hop on the n-tier/OOP bandwagon for my applications, but I've
hit one snag that I'm not sure the best way to proceed. Say a SqlException
is raised in my Data Access layer, that is a long long way from my
presentation layer/aspx page, where I would at least like to print out a
notification that an error was raised. How can I best achieve this in an
n-tier environment. It seems if I handle the error in my Data Access layer,
by the time the code execution gets back to the presentation layer, it won't
know what happened. Should I be defining my own object exceptions, and
raise them when I catch an error, and let it propigate itself up the
pipeline until the presentation layer can handle it?
Any help would be greatly appreciated!
--Michael
This is often handled exactly how you describe at the end of your post. The
data layer SqlException bubbles up to the Business Object layer which then
wraps that exception and re-raises with a more friendly strongly-typed
exception like OrderAddException when trying to call Order.Add. The
presentation layer (.aspx pages) then handles the OrderAddException and
presents a friendly message to the user like "Could not place your Order.
Please contact support here...."
--
Hope this helps,
Bryant Hankins
Numinet Systems Inc. http://www.numinet.com/blogging
"Raterus" <mo*********@suretar.reverse> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
Hello,
I'm trying to hop on the n-tier/OOP bandwagon for my applications, but I've
hit one snag that I'm not sure the best way to proceed. Say a SqlException
is raised in my Data Access layer, that is a long long way from my
presentation layer/aspx page, where I would at least like to print out a
notification that an error was raised. How can I best achieve this in an
n-tier environment. It seems if I handle the error in my Data Access layer,
by the time the code execution gets back to the presentation layer, it won't
know what happened. Should I be defining my own object exceptions, and
raise them when I catch an error, and let it propigate itself up the
pipeline until the presentation layer can handle it?
Any help would be greatly appreciated!
--Michael
That makes a lot of sense, I was actually experimenting with this method before I received any answers, and it works very well. Thanks!
"Bryant Hankins" <bryanthankins@_NO_SPAM_hotmail.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... This is often handled exactly how you describe at the end of your post. The data layer SqlException bubbles up to the Business Object layer which then wraps that exception and re-raises with a more friendly strongly-typed exception like OrderAddException when trying to call Order.Add. The presentation layer (.aspx pages) then handles the OrderAddException and presents a friendly message to the user like "Could not place your Order. Please contact support here...." -- Hope this helps, Bryant Hankins Numinet Systems Inc. http://www.numinet.com/blogging "Raterus" <mo*********@suretar.reverse> wrote in message news:eQ**************@TK2MSFTNGP09.phx.gbl... Hello, I'm trying to hop on the n-tier/OOP bandwagon for my applications, but I've hit one snag that I'm not sure the best way to proceed. Say a SqlException is raised in my Data Access layer, that is a long long way from my presentation layer/aspx page, where I would at least like to print out a notification that an error was raised. How can I best achieve this in an n-tier environment. It seems if I handle the error in my Data Access layer, by the time the code execution gets back to the presentation layer, it won't know what happened. Should I be defining my own object exceptions, and raise them when I catch an error, and let it propigate itself up the pipeline until the presentation layer can handle it? Any help would be greatly appreciated! --Michael
hmm, Is there a good reason why I shouldn't issue a throw ex?
Try
somethingThatCanCauseAnError()
Catch ex As Exception
Throw ex
End Try
I can understand creating a new ApplicationException with additional details, but sometimes all I need is the original exception details.
Thanks for your help,
--Michael
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eR**************@TK2MSFTNGP09.phx.gbl... Statement: "It seems if I handle the error in my DAL" Question: Can you actually handle the error (like, hit a backup database, or hit a cache which might be stale but will give some information) or can you just swallow it? I ask because my guess is that you can't actually handle it at the DAL layer - all you can do is catch it at the presentation layer and display a friendly error message. At that point, you have two options: 1 - let the exception bubble up (either don't catch it, or have an empty throw (don't do a Throw ex)) 2 - If, and only if, you can add additional information to the exception, rethrow a new exception (custom or not) making sure to include the original exception in there. (throw new ApplicationException("Doh", originalException)) Karl "Raterus" <mo*********@suretar.reverse> wrote in message news:eQ**************@TK2MSFTNGP09.phx.gbl... Hello, I'm trying to hop on the n-tier/OOP bandwagon for my applications, but I've hit one snag that I'm not sure the best way to proceed. Say a SqlException is raised in my Data Access layer, that is a long long way from my presentation layer/aspx page, where I would at least like to print out a notification that an error was raised. How can I best achieve this in an n-tier environment. It seems if I handle the error in my Data Access layer, by the time the code execution gets back to the presentation layer, it won't know what happened. Should I be defining my own object exceptions, and raise them when I catch an error, and let it propigate itself up the pipeline until the presentation layer can handle it? Any help would be greatly appreciated! --Michael
Throw ex rebundles the exception...I agree that what you want is the
original exception, that's what plain Throw does ...
If the exception thrown was an SqlException,you'll rethrow an Exception.
The original exception is still available in InnerException...but since you
you havent' added your own information, all you've managed to do is
obfuscate the important stuff.
Check out: http://dotnetguy.techieswithcats.com...s/004118.shtml for a
great explanation :)
Karl
"Raterus" <mo*********@suretar.reverse> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
hmm, Is there a good reason why I shouldn't issue a throw ex?
Try
somethingThatCanCauseAnError()
Catch ex As Exception
Throw ex
End Try
I can understand creating a new ApplicationException with additional
details, but sometimes all I need is the original exception details.
Thanks for your help,
--Michael
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:eR**************@TK2MSFTNGP09.phx.gbl... Statement: "It seems if I handle the error in my DAL" Question: Can you actually handle the error (like, hit a backup database,
or hit a cache which might be stale but will give some information) or can
you just swallow it?
I ask because my guess is that you can't actually handle it at the DAL layer - all you can do is catch it at the presentation layer and display a friendly error message. At that point, you have two options:
1 - let the exception bubble up (either don't catch it, or have an empty throw (don't do a Throw ex)) 2 - If, and only if, you can add additional information to the exception, rethrow a new exception (custom or not) making sure to include the
original exception in there. (throw new ApplicationException("Doh", originalException))
Karl
"Raterus" <mo*********@suretar.reverse> wrote in message news:eQ**************@TK2MSFTNGP09.phx.gbl... Hello,
I'm trying to hop on the n-tier/OOP bandwagon for my applications, but
I've hit one snag that I'm not sure the best way to proceed. Say a
SqlException is raised in my Data Access layer, that is a long long way from my presentation layer/aspx page, where I would at least like to print out a notification that an error was raised. How can I best achieve this in an n-tier environment. It seems if I handle the error in my Data Access
layer, by the time the code execution gets back to the presentation layer, it
won't know what happened. Should I be defining my own object exceptions, and raise them when I catch an error, and let it propigate itself up the pipeline until the presentation layer can handle it?
Any help would be greatly appreciated! --Michael
Good to know! Thanks, you have been very helpful!
--Michael
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:u2*************@TK2MSFTNGP11.phx.gbl... Throw ex rebundles the exception...I agree that what you want is the original exception, that's what plain Throw does ... If the exception thrown was an SqlException,you'll rethrow an Exception. The original exception is still available in InnerException...but since you you havent' added your own information, all you've managed to do is obfuscate the important stuff. Check out: http://dotnetguy.techieswithcats.com...s/004118.shtml for a great explanation :) Karl "Raterus" <mo*********@suretar.reverse> wrote in message news:er**************@TK2MSFTNGP09.phx.gbl... hmm, Is there a good reason why I shouldn't issue a throw ex? Try somethingThatCanCauseAnError() Catch ex As Exception Throw ex End Try I can understand creating a new ApplicationException with additional details, but sometimes all I need is the original exception details. Thanks for your help, --Michael "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eR**************@TK2MSFTNGP09.phx.gbl... Statement: "It seems if I handle the error in my DAL" Question: Can you actually handle the error (like, hit a backup database, or hit a cache which might be stale but will give some information) or can you just swallow it?
I ask because my guess is that you can't actually handle it at the DAL layer - all you can do is catch it at the presentation layer and display a friendly error message. At that point, you have two options:
1 - let the exception bubble up (either don't catch it, or have an empty throw (don't do a Throw ex)) 2 - If, and only if, you can add additional information to the exception, rethrow a new exception (custom or not) making sure to include the original exception in there. (throw new ApplicationException("Doh", originalException))
Karl
"Raterus" <mo*********@suretar.reverse> wrote in message news:eQ**************@TK2MSFTNGP09.phx.gbl... Hello,
I'm trying to hop on the n-tier/OOP bandwagon for my applications, but I've hit one snag that I'm not sure the best way to proceed. Say a SqlException is raised in my Data Access layer, that is a long long way from my presentation layer/aspx page, where I would at least like to print out a notification that an error was raised. How can I best achieve this in an n-tier environment. It seems if I handle the error in my Data Access layer, by the time the code execution gets back to the presentation layer, it won't know what happened. Should I be defining my own object exceptions, and raise them when I catch an error, and let it propigate itself up the pipeline until the presentation layer can handle it?
Any help would be greatly appreciated! --Michael
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hans-Joachim Widmaier |
last post by:
Hi all.
Handling files is an extremely frequent task in programming, so most
programming languages have an abstraction of the basic files offered by
the underlying operating system. This is...
|
by: Frank Puck |
last post by:
Meanwhile there are at least 8 years that compilers exist,
which provide a working implementation of C++ Exception Handling.
Has anything changed meanwhile?
From my point of view nothing has...
|
by: Ori |
last post by:
Hi,
I would like to create some mechanism to handle all the exceptions
which will happen in my application.
I have one form which is the base form while all the other forms
inherit from it.
...
|
by: C# Learner |
last post by:
Some time ago, I remember reading a discussion about the strengths and
weaknesses of exception handling. One of the weaknesses that was put
forward was that exception handling is inefficient (in...
|
by: Jesper Ordrup Christensen |
last post by:
Say I've created a piece of code that involves both sql, io and some number
conversions. Being a responsible developer I have tried to catch all of the
exceptions - but how can I be sure?
Is...
|
by: rawCoder |
last post by:
I have read that Exception Handling is expensive performance wise ( other
than Throw ) , but exactly how ?
Please consider the following example ...
////////////////// Code Block 1...
|
by: Garth Wells |
last post by:
I'm trying to create a DAL and am wondering what's the proper way to
handle errors in this Insert method.
public string Insert()
{
Database db = DatabaseFactory.CreateDatabase();
string...
|
by: Chuck Cobb |
last post by:
I'm implementing a centralized exception handling routine using the
Enterprise Library Exception Management Application Block.
I trap all unhandled exceptions to one place using the following...
|
by: jeffc226 |
last post by:
I'm interested in an idiom for handling errors in functions without
using traditional nested ifs, because I think that can be very awkward
and difficult to maintain, when the number of error checks...
|
by: eliben |
last post by:
Python provides a quite good and feature-complete exception handling
mechanism for its programmers. This is good. But exceptions, like any
complex construct, are difficult to use correctly,...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |