C Custom Error Messages
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Custom Error Messages Rails
about Stack Overflow the company Business Learn more about hiring developers or posting ads devise custom error messages with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow
Laravel Custom Error Messages
is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Printing error messages up vote 3 down vote favorite 2 I am just grails custom error messages wondering what is the best way to make custom print error functions. For example I have some #defines like this in header file: #define SOCKET_ERR 0 #define BIND_ERR 1 #define LISTEN_ERR 2 etc Then maybe using this like this: if(/*something has gone wrong with socket*/) { print_error(SOCKET_ERR); } print_error(int error) { if(error == 0) { printf("Socket failure\n"); } } However, I don't think this perfect and want to do how to make custom error messages something much better. Maybe something a little bit more professional and maybe more scalable. Many thanks for any advice, c share|improve this question asked Nov 5 '09 at 8:30 ant2009 55786241392 1 Use 'fprintf(stderr, ...)' to report errors (or, at least, normally write to 'stderr' rather than 'stdout' - or write to a log file, or both log file and stderr). –Jonathan Leffler Nov 5 '09 at 8:51 add a comment| 3 Answers 3 active oldest votes up vote 3 down vote accepted You might consider using variadic functions for error reporting, they become so much more versatile. For instance #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site
Woocommerce Custom Error Messages
About Us Learn more about Stack Overflow the company Business Learn more about c error function hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join
C Error Handling Best Practices
the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error handling in C http://stackoverflow.com/questions/1679117/printing-error-messages code up vote 102 down vote favorite 59 What do you consider "best practice" when it comes to error handling errors in a consistent way in a C library. There are two ways I've been thinking of: Always return error code. A typical function would look like this: MYAPI_ERROR getObjectSize(MYAPIHandle h, int* returnedSize); The always provide an error pointer approach: int getObjectSize(MYAPIHandle h, MYAPI_ERROR* returnedError); When http://stackoverflow.com/questions/385975/error-handling-in-c-code using the first approach it's possible to write code like this where the error handling check is directly placed on the function call: int size; if(getObjectSize(h, &size) != MYAPI_SUCCESS) { // Error handling } Which looks better than the error handling code here. MYAPIError error; int size; size = getObjectSize(h, &error); if(error != MYAPI_SUCCESS) { // Error handling } However, I think using the return value for returning data makes the code more readable, It's obvious that something was written to the size variable in the second example. Do you have any ideas on why I should prefer any of those approaches or perhaps mix them or use something else? I'm not a fan of global error states since it tends to make multi threaded use of the library way more painful. EDIT: C++ specific ideas on this would also be interesting to hear about as long as they are not involving exceptions since it's not an option for me at the moment... c error-handling share|improve this question edited Nov 6 '13 at 19:09 ubershmekel 3,61513144 asked Dec 22 '08 at 10:46 Laserallan 6,70172956 add a comment| 17 Answers 17 active oldest votes up
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow http://programmers.stackexchange.com/questions/209693/best-practices-to-create-error-codes-pattern-for-an-enterprise-project-in-c the company Business Learn more about hiring developers or posting ads with us Programmers Questions https://blog.golang.org/error-handling-and-go Tags Users Badges Unanswered Ask Question _ Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the custom error top Best Practices To Create Error Codes Pattern For an Enterprise Project in C# [closed] up vote 13 down vote favorite 15 I'm working on an enterprise project which will be deployed in many SMBs and Enterprises. The support for this project would be struggling and so I want to create a coding pattern for errors (Like HTTP status Codes). This will enable help desk people to refer to documents and custom error messages troubleshoot the problems as soon as possible. What are the best practices and recommendations to do this? Any help to do this will be useful. c# programming-practices error-handling enterprise-development share|improve this question edited Aug 28 '13 at 7:29 Kilian Foth 65.5k19179212 asked Aug 28 '13 at 6:58 Pooya 204127 closed as too broad by gnat, gbjbaanb, GlenH7, Yusubov, MichaelT Aug 28 '13 at 17:01 There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question. 1 There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. And what have you tried so far. –Ben McDougall Aug 28 '13 at 7:29 Depends on how your business is structured. In C# we always gave the user the possibility to mail us the StackTrace or copy/paste it from the error message details (we had no tight security requirements). –Falcon Aug 28
Mailing List Go on Google+ Go+ Community Go on Twitter Blog index The Go Blog Error handling and Go 12 July 2011 Introduction If you have written any Go code you have probably encountered the built-in error type. Go code uses error values to indicate an abnormal state. For example, the os.Open function returns a non-nil error value when it fails to open a file. func Open(name string) (file *File, err error) The following code uses os.Open to open a file. If an error occurs it calls log.Fatal to print the error message and stop. f, err := os.Open("filename.ext") if err != nil { log.Fatal(err) } // do something with the open *File f You can get a lot done in Go knowing just this about the error type, but in this article we'll take a closer look at error and discuss some good practices for error handling in Go. The error type The error type is an interface type. An error variable represents any value that can describe itself as a string. Here is the interface's declaration: type error interface { Error() string } The error type, as with all built in types, is predeclared in the universe block. The most commonly-used error implementation is the errors package's unexported errorString type. // errorString is a trivial implementation of error. type errorString struct { s string } func (e *errorString) Error() string { return e.s } You can construct one of these values with the errors.New function. It takes a string that it converts to an errors.errorString and returns as an error value. // New returns an error that formats as the given text. func New(text string) error { return &errorString{text} } Here's how you might use errors.New: func Sqrt(f float64) (float64, error) { if f < 0 { return 0, errors.New("math: square root of negative number") } // implementation } A caller passing a negative argument to Sqrt receives a non-nil error value (whose concrete representation is an errors.errorString value). The caller can access the error string ("math: square root of...") by calling the `error`'s Error method, or by just printing it: f, err := Sqrt(-1) if err != nil { fmt.Println(err) } The fmt package formats an error value by calling its Error() string method. It is the error implementation's responsibility to summarize the context. The error returned by os.Open formats as "open /etc/passwd: permission denied," not just "permission denied." The error returned by our Sqrt is missing information about the invalid argument