custom-exceptions

jQuery Ajax error handling, show custom exception messages

Is there some way I can show custom exception messages as an alert in my jQuery Ajax error message? For example, if I want to throw an exception on the server side via Struts by "throw new ApplicationException("User name already exists");", I want to catch this message (user name already exists) in the jQuery Ajax error message. jQuery...

How to know when to use an existing Exception or write a custom Exception?

Thanks for the input on this question, I've decided to go with making my Create() method throw exceptions so as Jon Skeet said, you don't have to handle them everywhere and can just let them bubble up, seems the best approach for larger applications. So now I create instances of my classes with this code: try { SmartForms smartForm...

How should I handle this particular exception in C#?

I have a class called "Website", and inside of that class I have the following property: public HtmlForm RegisterForm { get { if (Forms.RegForm != null) / Forms is a custom object called HTMLForms that is a custom list collection { return Forms.RegForm; } else { // ...

Why is it a "bad idea" to throw your own exceptions?

Why is it a "bad idea" to throw your own exceptions? found here ...

asp.net mvc custom exception filter to force a return of full view, not partial...

I have a custom exception filter that I'm calling by virtue of adding a [CustomExceptionFilter] attribute to my class. It works as I'd like it to, however if the action method is returning a partial view (through an ajax request), the exception (which is basically a redirect to a not authorized page), is loading up the partial view with...

C# Webservice: Throw exception with extra properties in JSON

I have a webservice written in C#. When errors occur on the server, I would like to inform the user client side. This works fine by throwing exceptions server side, which is then sent to my error handler client side. However, I would like to, when I throw the exception, to set a property describing how serious I think the error is at th...

Catch Multiple Custom Exceptions? - C++

Hi all, I'm a student in my first C++ programming class, and I'm working on a project where we have to create multiple custom exception classes, and then in one of our event handlers, use a try/catch block to handle them appropriately. My question is: How do I catch my multiple custom exceptions in my try/catch block? GetMessage() is a ...

Exception design: Custom exceptions reading data from file?

I have a method that reads data from a comma separated text file and constructs a list of entity objects, let's say customers. So it reads for example, Name Age Weight Then I take these data objects and pass them to a business layer that saves them to a database. Now the data in this file might be invalid, so I'm trying to figure ou...

How to create custom exception handler for custom controls or extension methods.

I am creating an extension method in C# to retrieve some value from datagridview. Here if a user gives column name that doesnot exists then i want this function to throw an exception that can be handled at the place where this function will be called. How can i achieve this. public static T Value<T>(this DataGridView dgv, int RowNo,...

Conventions for Assembling Multiple Error Message Exceptions

I have a list of validations to run against an object, each a separate method which takes the object as a parameter. As each validation fails, I will create an appropriate error message. At the end of the validation process, I will throw a custom exception containing a list of all the error messages. My question is, I've seen this don...

What type of exception to throw in this case?

I'm writing a c# application which uses automation to control another program. Naturally that program must be running for my program to work. When my program looks for the application and can't find it I'd like to throw an exception (for now later of course I could try opening the application, or telling the user to open it, or ...). Sh...

Silverlight exception (faults) handling from wcf service

I want get exeption code from wcf method but i always get NotFound error. Client Side: public MainPage() { InitializeComponent(); client.TestCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(TestCompleted); } void TestCompleted(object sender, System.ComponentModel.AsyncCompletedEv...

.net exceptions

When should I create my own custom exception class rather than using a one provided by .Net? Which base exception class should I derive from and why? ...

symfony - save method override and exceptions management

Hi! Currently, I am developing an application which domain model should prevent objects duplication according the equality or not of some object fields. So, I am thinking to handle this comparison on the save method of the class: if some existing object has some properties equal to the object to be saved, the save should be prevented. ...

Custom Exceptions: Differentiate via many subclasses or single class backed with enum?

I'm looking to implement my own set of Exceptions for a projects I am currently working on. The project relies on a core framework with a base framework exception MyFrameworkException (I am also writing this framework). For any given project I would like to throw several different types of Exceptions and I can't decide between using mul...

ASP.NET MVC 2 Model Errors with Custom Exceptions

Hi Guys, I have a custom exception class: public class MyException: Exception { public MyException(MyExceptionEnum myError) : base(myError.ToDescription()) { } public MyException(MyExceptionEnum myError, Exception innerException) : base(myError.ToDescription(), innerException) { } } .ToDescription is a extension method on MyExc...