If I was to have my biz layer ask the data layer to load a particular object
based on key field info i pass to it, and it cannot create the object
becaues it isnt' in the Db, should the data layer pass back an exception or
a null reference?
if an exception, i would imagine i should catch this and display a message
to the user?
thanks 12 1775
TS wrote:
If I was to have my biz layer ask the data layer to load a particular
object based on key field info i pass to it, and it cannot create the
object becaues it isnt' in the Db, should the data layer pass back an
exception or a null reference?
if an exception, i would imagine i should catch this and display a message
to the user?
I would prefer some non-exception indicator that the record was not found.
If you want to return a null object, that would work. Don't forget to check
for null as you will get a null reference exception if you try to access the
object without checking for a null object reference first.
You might also consider using some other indicator such as a status code or
bool value that indicates whether or not the object was successfully created
from the DB.
--
Tom Porterfield
Exceptions should be "Exceptional"
Thus, if this is something you except to happen, then return a null.
"Tom Porterfield" <tp******@mvps.orgwrote in message
news:ek**************@TK2MSFTNGP03.phx.gbl...
TS wrote:
If I was to have my biz layer ask the data layer to load a particular
object based on key field info i pass to it, and it cannot create the
object becaues it isnt' in the Db, should the data layer pass back an
exception or a null reference?
if an exception, i would imagine i should catch this and display a
message
to the user?
I would prefer some non-exception indicator that the record was not found.
If you want to return a null object, that would work. Don't forget to
check
for null as you will get a null reference exception if you try to access
the
object without checking for a null object reference first.
You might also consider using some other indicator such as a status code
or
bool value that indicates whether or not the object was successfully
created
from the DB.
--
Tom Porterfield
An exceptional comment from an exceptional guy.
:-)
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"sloan" wrote:
>
Exceptions should be "Exceptional"
Thus, if this is something you except to happen, then return a null.
"Tom Porterfield" <tp******@mvps.orgwrote in message
news:ek**************@TK2MSFTNGP03.phx.gbl...
TS wrote:
If I was to have my biz layer ask the data layer to load a particular
object based on key field info i pass to it, and it cannot create the
object becaues it isnt' in the Db, should the data layer pass back an
exception or a null reference?
>
if an exception, i would imagine i should catch this and display a
message
to the user?
I would prefer some non-exception indicator that the record was not found.
If you want to return a null object, that would work. Don't forget to
check
for null as you will get a null reference exception if you try to access
the
object without checking for a null object reference first.
You might also consider using some other indicator such as a status code
or
bool value that indicates whether or not the object was successfully
created
from the DB.
--
Tom Porterfield
"TS" <ma**********@nospam.nospamwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
If I was to have my biz layer ask the data layer to load a particular
object based on key field info i pass to it, and it cannot create the
object becaues it isnt' in the Db, should the data layer pass back an
exception or a null reference?
I can think of a few different approaches to this.
1) null reference - you check that the object == null and handle accordingly
2) throw an exception - you catch the exception and handle accordingly
3) return a Null Object - you encapsulate the behavior of what to do when
the ID was not found into the object itself.
4) return a default object - you use another object as the default object
when the ID was not found
5) create an object with default values - you create an object with default
values and return this
What is the reason that the ID was not found in the database? Is this
something critical or something that is expected and you want to handle this
gracefully? If it is expected then do not throw an exception.
PS
For example
>
if an exception, i would imagine i should catch this and display a message
to the user?
On Mon, 13 Nov 2006 14:39:43 -0600, "TS" <ma**********@nospam.nospam>
wrote:
>If I was to have my biz layer ask the data layer to load a particular object based on key field info i pass to it, and it cannot create the object becaues it isnt' in the Db, should the data layer pass back an exception or a null reference?
if an exception, i would imagine i should catch this and display a message to the user?
thanks
I guess it would depend on your application design. If NOT finding a
record with a given primary key is part of the application design i.e.
is part of the functionality then perhaps a null would suffice.
Personally I would throw an exception and handle that in the UI
Hi TS,
In my opinion, if you're returning some status code, it will be better if
you can have some status code for database not found. If you return the
object directly to the biz layer, I would suggest you throw an exception,
which makes difference to the certain data is not found.
If anything is unclear, please feel free to let me know.
Kevin Yu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
this is something that happens infrequently in production system
"PS" <ec***********@hotmail.comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>
"TS" <ma**********@nospam.nospamwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
>If I was to have my biz layer ask the data layer to load a particular object based on key field info i pass to it, and it cannot create the object becaues it isnt' in the Db, should the data layer pass back an exception or a null reference?
I can think of a few different approaches to this.
1) null reference - you check that the object == null and handle
accordingly
2) throw an exception - you catch the exception and handle accordingly
3) return a Null Object - you encapsulate the behavior of what to do when
the ID was not found into the object itself.
4) return a default object - you use another object as the default object
when the ID was not found
5) create an object with default values - you create an object with
default values and return this
What is the reason that the ID was not found in the database? Is this
something critical or something that is expected and you want to handle
this gracefully? If it is expected then do not throw an exception.
PS
For example
>> if an exception, i would imagine i should catch this and display a message to the user?
TS wrote:
this is something that happens infrequently in production system
But that doesn't answer the important question. Is it truly unexpected, or
exceptional, behavior when the record isn't found. If it's not then you
shouldn't throw an exception. If it is, then that designed has more merit.
--
Tom Porterfield
"TS" <ma**********@nospam.nospamwrote in message
news:uT**************@TK2MSFTNGP02.phx.gbl...
this is something that happens infrequently in production system
And how does it happen? I mean how is it that the application manages to
know a key that does NOT exist in the database? Where does it get the keys
from?
>
"PS" <ec***********@hotmail.comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>> "TS" <ma**********@nospam.nospamwrote in message news:uA**************@TK2MSFTNGP02.phx.gbl...
>>If I was to have my biz layer ask the data layer to load a particular object based on key field info i pass to it, and it cannot create the object becaues it isnt' in the Db, should the data layer pass back an exception or a null reference?
I can think of a few different approaches to this.
1) null reference - you check that the object == null and handle accordingly 2) throw an exception - you catch the exception and handle accordingly 3) return a Null Object - you encapsulate the behavior of what to do when the ID was not found into the object itself. 4) return a default object - you use another object as the default object when the ID was not found 5) create an object with default values - you create an object with default values and return this
What is the reason that the ID was not found in the database? Is this something critical or something that is expected and you want to handle this gracefully? If it is expected then do not throw an exception.
PS
For example
>>> if an exception, i would imagine i should catch this and display a message to the user?
Ok, what happens is i am getting an exception in production for when 2
browsers have a web page open showing a specific record. The one browser
deletes the record. The other browser then tries to do something with it
(delete it, edit it, save it, view it, etc) and the code behind tries to
load that record to save the new value into it and it no longer exists. Its
a rare thing but does happen. The methods are set up to throw exceptions if
a record isn't found based on the key values that are sent to it (id of the
record in the DB).
thanks for your posts guys!!!
"PS" <ec***********@hotmail.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
>
"TS" <ma**********@nospam.nospamwrote in message
news:uT**************@TK2MSFTNGP02.phx.gbl...
>this is something that happens infrequently in production system
And how does it happen? I mean how is it that the application manages to
know a key that does NOT exist in the database? Where does it get the keys
from?
>>
"PS" <ec***********@hotmail.comwrote in message news:uX**************@TK2MSFTNGP03.phx.gbl...
>>> "TS" <ma**********@nospam.nospamwrote in message news:uA**************@TK2MSFTNGP02.phx.gbl... If I was to have my biz layer ask the data layer to load a particular object based on key field info i pass to it, and it cannot create the object becaues it isnt' in the Db, should the data layer pass back an exception or a null reference?
I can think of a few different approaches to this.
1) null reference - you check that the object == null and handle accordingly 2) throw an exception - you catch the exception and handle accordingly 3) return a Null Object - you encapsulate the behavior of what to do when the ID was not found into the object itself. 4) return a default object - you use another object as the default object when the ID was not found 5) create an object with default values - you create an object with default values and return this
What is the reason that the ID was not found in the database? Is this something critical or something that is expected and you want to handle this gracefully? If it is expected then do not throw an exception.
PS
For example
if an exception, i would imagine i should catch this and display a message to the user?
TS wrote:
Ok, what happens is i am getting an exception in production for when 2
browsers have a web page open showing a specific record. The one browser
deletes the record. The other browser then tries to do something with it
(delete it, edit it, save it, view it, etc) and the code behind tries to
load that record to save the new value into it and it no longer exists.
Its a rare thing but does happen. The methods are set up to throw
exceptions if a record isn't found based on the key values that are sent
to it (id of the record in the DB).
So it's a concurrency issue. Are you also handling the update/update
scenario? This one won't throw exceptions, unless you allow updating of
primary/unique keys, but can lead to data loss.
This is one where the more users you have, the more likely you are to run
into this. You need to employ a mechanism to make sure that your data is
fresh. You need to decide how you want to handle this.
In your scenario I would not use exceptions but instead use return codes.
--
Tom Porterfield
"TS" <ma**********@nospam.nospamwrote in message
news:eP**************@TK2MSFTNGP03.phx.gbl...
Ok, what happens is i am getting an exception in production for when 2
browsers have a web page open showing a specific record. The one browser
deletes the record. The other browser then tries to do something with it
(delete it, edit it, save it, view it, etc) and the code behind tries to
load that record to save the new value into it and it no longer exists.
Its a rare thing but does happen. The methods are set up to throw
exceptions if a record isn't found based on the key values that are sent
to it (id of the record in the DB).
thanks for your posts guys!!!
You have a concurrecy issue then. With optimistic locking this is to be
expected (and is not an exception). And it is not just on deletes that you
need to be concerned. With optimistic locking you also need to check that
the underlying record was not changed in the meantime by another user
otherwise changes made by one user are written over by another user (aka
inconsisten read). Therefore you need to handle both deleted and edited
objects accordingly. Alternatively you can use a pessimistic locking scheme
so that no one can edit/delete any object that is being edited/deleted by
another user.
>
"PS" <ec***********@hotmail.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
>> "TS" <ma**********@nospam.nospamwrote in message news:uT**************@TK2MSFTNGP02.phx.gbl...
>>this is something that happens infrequently in production system
And how does it happen? I mean how is it that the application manages to know a key that does NOT exist in the database? Where does it get the keys from?
>>>
"PS" <ec***********@hotmail.comwrote in message news:uX**************@TK2MSFTNGP03.phx.gbl...
"TS" <ma**********@nospam.nospamwrote in message news:uA**************@TK2MSFTNGP02.phx.gbl... If I was to have my biz layer ask the data layer to load a particular object based on key field info i pass to it, and it cannot create the object becaues it isnt' in the Db, should the data layer pass back an exception or a null reference?
I can think of a few different approaches to this.
1) null reference - you check that the object == null and handle accordingly 2) throw an exception - you catch the exception and handle accordingly 3) return a Null Object - you encapsulate the behavior of what to do when the ID was not found into the object itself. 4) return a default object - you use another object as the default object when the ID was not found 5) create an object with default values - you create an object with default values and return this
What is the reason that the ID was not found in the database? Is this something critical or something that is expected and you want to handle this gracefully? If it is expected then do not throw an exception.
PS
For example
> if an exception, i would imagine i should catch this and display a message to the user? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: DrUg13 |
last post by:
In java, this seems so easy. You need a new object
Object test = new Object() gives me exactly what I want.
could someone please help me understand the different ways to do the
same thing in...
|
by: Herve MAILLARD |
last post by:
Hi,
I have to write a software doing the following :
- Load a file (containing data)
Data will be display in a Treeview and are typed as following
Equipement
Bloc
Tag
It could have for each...
|
by: 42 |
last post by:
Hi,
Stupid question:
I keep bumping into the desire to create classes and properties with the
same name and the current favored naming conventions aren't
automatically differentiating them......
|
by: cbrown |
last post by:
I am rebuilding an existing application that relies on an SQL DB. The
app is a scheduling/employee management program. My question pertains
to best practices in dotnet and database.
I use a 3...
|
by: Alan Silver |
last post by:
Hello,
MSDN (amongst other places) is full of helpful advice on ways to do data
access, but they all seem geared to wards enterprise applications. Maybe
I'm in a minority, but I don't have those...
|
by: Rex |
last post by:
Hi All - I have a question that I think MIGHT be of interest to a
number of us developers. I am somewhat new to VIsual Studio 2005 but
not new to VB. I am looking for ideas about quick and...
|
by: G |
last post by:
Hello,
Looking for opinions on a fairly simple task, new to ASP.net (C#) and want
to make sure I do this as efficiently as possible.
I have a web based form, and I need to run some SQL before...
|
by: Steve |
last post by:
I am building an object library for tables in a database. What is the
best practice for creating objects like this?
For example, say I have the following tables in my database:
User:
- Id
-...
|
by: Gabriel |
last post by:
Hello,
I'm looking for documentation with "Best Practice" for ASP.NET application
In which case use Connected or Disconnected mode
Typed dataset or not ?
I didn'd find anything pertinent...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |