c# - Error handling - global error catalog? -


back when writing c code might have used global #defines error numbers. can't in c#. use error class, i'd have pass around. such serious faux pas have global error catalog class? class containing, example, dictionary of errors , messages? how handled better?

ok, have been clearer... sorry.

let's accessing database, or several databases, in different classes. if error accessing database want display error message of sort, don't want display system generated error message - have own error catalog want use. let's have standard "database access error" string want show, want add database name , table. achieve couple of #defines in c. how should handle c# - singleton class globally accessible contains dictionary? bad thing?

if want define custom dictionary code , message work you, it's not practice. if code become more , more larger, giving meaningful name exception better code. think when there more 1 person work on project if use customclass more easier intellisense come in help.

in c# works in different way can use custom exception class each c code have defined

using system;  public class employeelistnotfoundexception: exception {     int _codeexception;      public employeelistnotfoundexception()     {      }      public employeelistnotfoundexception(string message,int codeexception)         : base(message)     {                   _codeexception=codeexception;      }      public employeelistnotfoundexception(string message, exception inner)         : base(message, inner)     {      }    public int codeexception{get {return _codeexception;} } } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -