RE: How to get rid of Bad Coding Habits /// return status

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hehe.
You have to be patient, Sloan.
Explain to them that the caller of this method should wrap their call in a
try / catch block and be prepared to accept the fact that they may get back
an exception.

And just explain why they should not populate some return "string" with the
exception message property and instead, throw the actual exception itself.

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"sloan" wrote:



Does anyone have any good articles on Exception Handing in DotNet.
As a "get rid of the API mode of knowing if something worked, we're not in
VB6 land anymore Dorothy".


I have a few people at work who keep writing code like below.


public string UpdateEmployee
{
string returnStatus = string.Empty;
try {
Database db = this.GetDatabase();
DbCommand dbCommand = db.GetStoredProcCommand("dbo.[uspAAAAAAAAAAAAAA]");
(dbCommand);

db.ExecuteNonQuery(dbCommand);


}



catch (Exception ex) {
sStatus = "ERROR updating Examiner table: " + ex.Message;
}


return returnStatus;

}


and I need some reference(s) to put a stop to this mess.


At least with API, you checked for = or != to 0.

err.Number
case --020303000003003
msg = "The blah blah blah failed"

Those were good times.

Any good articles are appreciated (esp if the directly tackle this
situation )








.



Relevant Pages

  • RE: Detailed ASP.Net info not displaying in browser
    ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.xml)
  • RE: Detailed ASP.Net info not displaying in browser
    ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.xml)
  • Re: App_data - ASPNETDB.MDF
    ... is only because I want my site work, without exception. ... Server Error in '/' Application. ... serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Error handling not working
    ... Dim exception As Exception = Server.GetLastError.GetBaseException ... Dim ErrorString as String ... GetBaseException retrieves the "real" innerException object. ... CustomErrors in my webconfig file: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Could not load file or assembly...
    ... The problem shows when EL exception handling ... context, ExceptionHandlerData objectConfiguration, IConfigurationSource ... configurationSource, ConfigurationReflectionCache reflectionCache) ... context, String name, IConfigurationSource configurationSource, ...
    (microsoft.public.dotnet.framework)