Questions tagged [custom-exceptions]

Custom Exception inherits the properties from the Exception class. Whenever we declare our own exception, it is known as custom exception.

Custom Exception inherits the properties from the Exception class. Whenever we declare our own exception, it is known as custom exception.

242 questions
3
votes
3 answers

Custom Exceptions

I'm trying to define my own custom exceptions. Basically i want to prevent a user to be created if the age is less than 16. Following some of the discussions / questions i've come up with this so far. public enum Code { USER_INVALID_AGE("The…
Alex L
  • 163
  • 1
  • 1
  • 8
3
votes
1 answer

Stopping "not handled in user code" dialog for exception type

Within visual studio I get an dialog saying something like "An exception of type XXX occurred in YYY.dll but was not handled in user code" and pausing my code. Is there a way in VS2013 of suppressing this just for this one exception type (this…
Nick Tucker
  • 323
  • 7
  • 14
3
votes
3 answers

Unit test a custom Exception

My code coverage has listed my custom exception as 0 test coverage. I am using MsTest,Moq and Fluentassertions. Is there an appropriate unit test for a custom exception? Here is my Exception class public class ConfigurationNotFoundException :…
MicroMan
  • 1,988
  • 4
  • 32
  • 58
3
votes
1 answer

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…
Chau
  • 5,540
  • 9
  • 65
  • 95
3
votes
2 answers

python: raise("customException") - why no stack trace?

Using custom exceptions in python (v2.7.3): don't get a stack trace when call getSub() whereas getSub(True) invokes one, the difference being that it is caused via an additional try...except which I want to avoid (+feels unnecessary) so why/how can…
macib
  • 31
  • 4
3
votes
1 answer

Shorter way to define custom JavaScript exceptions?

I'm defining custom JavaScript exceptions like the code below. Is this proper? Isn't there a shorter way? function InvalidModuleError(moduleName) { TypeError.apply(this); this.message = "module '" + moduleName + "' doesn't export any…
HankMoody
  • 3,077
  • 1
  • 17
  • 38
3
votes
4 answers

Custom exceptions and base constructor

I've been trying to write my own custom constructor, but getting error about base() constructor. I've also been searching how to solve this error, but found nothing and all the examples round the internet are showing almost the same code as…
Masius
  • 326
  • 1
  • 6
  • 17
3
votes
3 answers

Handling exceptions for multiple calls to functions of a class

I can't get my head around WHEN to throw and catch exceptions for when I call functions from classes. Please imagine that my QuizMaker class looks like this: // Define exceptions for use in class private class CreateQuizException extends Exception…
Luke
  • 22,826
  • 31
  • 110
  • 193
2
votes
3 answers

c# exception questions

Thank you all for helping. This code doesn't produce what I expect when the divisor is 1. The base class for ExceptOne doesn't get called, the hyperlink in ExceptOne doesn't get displayed. What am I missing ?! Console output is: enter a divisor …
steelponey
  • 55
  • 1
  • 5
2
votes
1 answer

Custom Exceptions and reducing duplicated code

I have decided to use Exceptions in my code to pass error handling around. I found myself duplicating code each time I wanted to create a new exception. These classes were nothing special and only contained a messaged. But I have come to rely on…
MarkP
  • 4,168
  • 10
  • 43
  • 84
2
votes
2 answers

How to handle Unchecked / Runtime Exceptions in MULE.?

Does anybody know how to handle Unchecked / Runtime Exceptions in MULE..?? I mean, in my java code, for a certain reason , i am "throwing an Exception" and i want Mule to detect it and route it to proper flow , where i can Log or Print that…
Ramandeep Singh
  • 5,063
  • 3
  • 28
  • 34
2
votes
6 answers

Pros and Cons of implementing a generic custom exception

What are the pros and cons of implementing a custom exception as follows: Create an enum which represents error messages in its descriptions: public class Enums { public enum Errors { [Description("This is a test exception")] …
Kamyar
  • 18,639
  • 9
  • 97
  • 171
2
votes
2 answers

How do I create a subclass with a constructor that defaults the helplink to google.com?

I'm trying to write code to create an EpicFailException class as a subclass of ApplicationException. I have to add a constructor that defaults the HelpLink property to google.com. Below is what I have so far. Any suggestions for how to apply the…
John
  • 21
  • 1
2
votes
3 answers

Custom Exception Type is 'self logging' - is that bad?

I'm on a project where the team has defined a custom exception type, in the constructor of which is a call to a Logging method which logs the exception passed into the constructor. I would have thought that this was bad - is it? The problem is that…
Adrian K
  • 9,880
  • 3
  • 33
  • 59
2
votes
2 answers

C#: should I throw an ArgumentException or NotSupportedException when an argument type is not supported?

So, I've got a situation where I need to throw an exception because "an argument is not supported". To explain how I got here, this is the rough situation: Ooks come in many types, including Yooks and Zooks Ooks can befriend other Ooks, but only of…