![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I'm wondering when does Debug.Assert is pertinent to use. For the moment, I think it is used to ensure something is true, as it is supposed to be always true. For example, I query a DB to get the only one customer's detail rows. If I get any exception, it is an runtime error..So I use try/catch/throw blocks. If I get 0 rows, it is a business error, so I throw a business exception. If I get 1 row, it's ok and I return it. If I get 2 or more row, it's a supposed-impossible case, but I use Debug.Assert to check it actually does not occurs. If it occurs, it should help me debug the application. Am I on the right way ? Steve |
#3
| |||
| |||
|
|
Hi, I'm wondering when does Debug.Assert is pertinent to use. For the moment, I think it is used to ensure something is true, as it is supposed to be always true. For example, I query a DB to get the only one customer's detail rows. If I get any exception, it is an runtime error..So I use try/catch/throw blocks. If I get 0 rows, it is a business error, so I throw a business exception. If I get 1 row, it's ok and I return it. If I get 2 or more row, it's a supposed-impossible case, but I use Debug.Assert to check it actually does not occurs. If it occurs, it should help me debug the application. Am I on the right way ? |
#4
| |||
| |||
|
|
Steve, you should use error handling code (exceptions) for conditions you expect to occur and assertions for conditions that should never occur. In other words, the general strategy is to use asserts everywhere where something must to be true and it not being true would be a programming error of some type. Exceptions should be used where it is an error condition that could happen in a real system but is relatively unusual (like your method not returning a record). Imho your approach is right. Markus "Steve B." <steve_beauge (AT) com (DOT) msn_swap_com_and_msn> schrieb im Newsbeitrag news:O5PTtATlGHA.3816 (AT) TK2MSFTNGP02 (DOT) phx.gbl... Hi, I'm wondering when does Debug.Assert is pertinent to use. For the moment, I think it is used to ensure something is true, as it is supposed to be always true. For example, I query a DB to get the only one customer's detail rows. If I get any exception, it is an runtime error..So I use try/catch/throw blocks. If I get 0 rows, it is a business error, so I throw a business exception. If I get 1 row, it's ok and I return it. If I get 2 or more row, it's a supposed-impossible case, but I use Debug.Assert to check it actually does not occurs. If it occurs, it should help me debug the application. Am I on the right way ? Steve |
#5
| |||
| |||
|
|
Hi, I'm wondering when does Debug.Assert is pertinent to use. For the moment, I think it is used to ensure something is true, as it is supposed to be always true. For example, I query a DB to get the only one customer's detail rows. If I get any exception, it is an runtime error..So I use try/catch/throw blocks. If I get 0 rows, it is a business error, so I throw a business exception. If I get 1 row, it's ok and I return it. If I get 2 or more row, it's a supposed-impossible case, but I use Debug.Assert to check it actually does not occurs. If it occurs, it should help me debug the application. Am I on the right way ? Steve |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |