custom-exceptions

Custom Python Exceptions with Error Codes and Error Messages

心已入冬 提交于 2019-11-29 20:37:33
class AppError(Exception): pass class MissingInputError(AppError): pass class ValidationError(AppError): pass ... def validate(self): """ Validate Input and save it """ params = self.__params if 'key' in params: self.__validateKey(escape(params['key'][0])) else: raise MissingInputError if 'svc' in params: self.__validateService(escape(params['svc'][0])) else: raise MissingInputError if 'dt' in params: self.__validateDate(escape(params['dt'][0])) else: raise MissingInputError def __validateMulti(self, m): """ Validate Multiple Days Request""" if m not in Input.__validDays: raise ValidationError

FaultException and custom exception WCF

风流意气都作罢 提交于 2019-11-29 11:13:30
I have a question on how to send a custom exception as FaultException. It works when I use a system Exception like ArgumentException, but if I change it to my custom exception "TestException" it fails. I can’t get the configuration for the service reference, when I try to add it. Works: [OperationContract] [FaultContract(typeof(ArgumentException))] [TransportChannel TestMethod (); public Void TestMethod() { throw new FaultException<ArgumentException>(new ArgumentException("test"), new FaultReason("test")); } Doesn’t work: [OperationContract] [FaultContract(typeof(TestException))]

Wrap jQuery's $.ajax() method to define global error handling

折月煮酒 提交于 2019-11-29 05:31:21
Branching off of questions like this one , I'm looking to wrap jQuery's $.ajax() method such that I can provide error handling in one location, which would then be used automatically by all of an application's remote calls. The simple approach would be to simply create a new name, similar to how $.get() and $.post() implement facades to $.ajax(). However, I'm hoping to reuse the name $.ajax(), such that we can keep the rest of our code using the standard jQuery syntax, hiding from it the fact that we've added our own error handling. Is this practical and/or good to achieve, or possibly a

Throwing custom exceptions in Javascript. Which style to use?

醉酒当歌 提交于 2019-11-28 22:28:45
问题 Douglas Crockford recommends doing something like this: throw { name: "System Error", message: "Something horrible happened." }; But you could also do something like this: function IllegalArgumentException(message) { this.message = message; } throw new IllegalArgumentException("Argument cannot be less than zero"); and then do: try { //some code that generates exceptions } catch(e) { if(e instanceof IllegalArgumentException) { //handle this } else if(e instanceof SomeOtherTypeOfException) { /

How to create exceptions?

会有一股神秘感。 提交于 2019-11-28 19:23:39
So I have an upcoming assignment dealing with exceptions and using them in my current address book program that most of the homework is centered around. I decided to play around with exceptions and the whole try catch thing, and using a class design, which is what I will eventually have to do for my assignment in a couple of weeks. I have working code that check the exception just fine, but what I want to know, is if there is a way to standardize my error message function, (i.e my what() call): Here s my code: #include <iostream> #include <exception> using namespace std; class testException:

Exception handler in Spring MVC

若如初见. 提交于 2019-11-28 17:35:29
I want to create an exception handler which will intercept all controllers in my project. Is that possible to do? Looks like I have to put a handler method in each controller. Thanks for your help. I have a spring controller that sends Json response. So if an exception happens I want to send an error response which can be controlled from one place. Ralph (I found a way to implement it in Spring 3.1, this is described in the second part of this answer) See chapter 16.11 Handling exceptions of Spring Reference There are some more ways than using @ExceptionHandler (see gouki's answer ) You could

Ruby custom error classes: inheritance of the message attribute

风流意气都作罢 提交于 2019-11-28 15:33:36
I can't seem to find much information about custom exception classes. What I do know You can declare your custom error class and let it inherit from StandardError , so it can be rescue d: class MyCustomError < StandardError end This allows you to raise it using: raise MyCustomError, "A message" and later, get that message when rescuing rescue MyCustomError => e puts e.message # => "A message" What I don't know I want to give my exception some custom fields, but I want to inherit the message attribute from the parent class. I found out reading on this topic that @message is not an instance

What are industry standard best practices for implementing custom exceptions in C#?

五迷三道 提交于 2019-11-27 11:17:35
What are industry standard best practices for implementing custom exceptions in C#? I have checked Google and there's a great number of recommendations, however I don't know which ones hold more credibility. If anybody has any links to authoritative articles, that would also be helpful. James The standard for creating custom exceptions is to derive from Exception . You can then introduce your own properties/methods and overloaded constructors (if applicable). Here is a basic example of a custom ConnectionFailedException which takes in an extra parameter which is specific to the type of

Ruby custom error classes: inheritance of the message attribute

不问归期 提交于 2019-11-27 09:15:39
问题 I can't seem to find much information about custom exception classes. What I do know You can declare your custom error class and let it inherit from StandardError , so it can be rescue d: class MyCustomError < StandardError end This allows you to raise it using: raise MyCustomError, "A message" and later, get that message when rescuing rescue MyCustomError => e puts e.message # => "A message" What I don't know I want to give my exception some custom fields, but I want to inherit the message

C#: Throwing Custom Exception Best Practices

送分小仙女□ 提交于 2019-11-27 03:37:43
I have read a few of the other questions regarding C# Exception Handling Practices but none seem to ask what I am looking for. If I implement my own custom Exception for a particular class or set of classes. Should all errors that relate to those classes be encapsulated into my exception using inner exception or should I let them fall through? I was thinking it would be better to catch all exceptions so that the exception can be immediately recognized from my source. I am still passing the original exception as an inner exception. On the other hand, I was thinking it would be redundant to