Custom exception type
Can I define custom types for user-defined exceptions in JavaScript? If so, how would I do it? 13 Answers 13
Can I define custom types for user-defined exceptions in JavaScript? If so, how would I do it? 13 Answers 13
I want to have a way to report the stack trace to the user if an exception is thrown. What is the best way to do this? Does it take huge amounts of extra code? To answer questions: I’d like it to be portable if possible. I want information to pop up, so the user … Read more
I have code that is logging Exception.Message. However, I read an article which states that it’s better to use Exception.ToString(). With the latter, you retain more crucial information about the error. Is this true, and is it safe to go ahead and replace all code logging Exception.Message? I’m also using an XML based layout for … Read more
In a catch block, how can I get the line number which threw an exception? 13 Answers 13
I’ve been a professional software engineer for about a year now, having graduated with a CS degree. I’ve known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET at all until recently. Our production code contains no asserts whatsoever and my question is this… Should … Read more
When is it right for a constructor to throw an exception? (Or in the case of Objective C: when is it right for an init’er to return nil?) It seems to me that a constructor should fail — and thus refuse to create an object — if the object isn’t complete. I.e., the constructor should … Read more
I know that print(e) (where e is an Exception) prints the occurred exception but, I was trying to find the python equivalent of Java’s e.printStackTrace() that exactly traces the exception to what line it occurred and prints the entire trace of it. Could anyone please tell me the equivalent of e.printStackTrace() in Python? 4 Answers … Read more
Try-catch is meant to help in the exception handling. This means somehow that it will help our system to be more robust: try to recover from an unexpected event. We suspect something might happen when executing and instruction (sending a message), so it gets enclosed in the try. If that something nearly unexpected happens, we … Read more
In Java (or any other language with checked exceptions), when creating your own exception class, how do you decide whether it should be checked or unchecked? My instinct is to say that a checked exception would be called for in cases where the caller might be able to recover in some productive way, where as … Read more
For some reason it looks like constructor delegation doesn’t work in the following snippet: function NotImplementedError() { Error.apply(this, arguments); } NotImplementedError.prototype = new Error(); var nie = new NotImplementedError(“some message”); console.log(“The message is: ‘”+nie.message+”‘”) Running this gives The message is: ”. Any ideas as to why, or if there is a better way to create … Read more