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
15
votes
3 answers

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…
Andy
  • 5,108
  • 3
  • 26
  • 37
13
votes
1 answer

PostgreSQL custom exception conditions

Is it possible to create custom conditions when I raise an exception? Consider the following example: BEGIN y := x / 0; EXCEPTION WHEN division_by_zero THEN RAISE NOTICE 'caught division_by_zero'; RETURN x; END; Here…
Snifff
  • 1,784
  • 2
  • 16
  • 28
12
votes
1 answer

Catching custom exception in c#

I have created a custom exception class as below namespace testingEXception { public class CustomException : Exception { public CustomException() { } public CustomException(string message) …
Hataf Moin
  • 161
  • 1
  • 2
  • 9
12
votes
3 answers

Organizing Custom Exceptions in C#

I am creating a C# application and am trying to take advantage of custom exceptions when appropriate. I've looked at other questions here and at the MSDN design guidelines but didn't come across anything as specific as what I'm wondering here. What…
Kyle Tolle
  • 694
  • 2
  • 7
  • 17
11
votes
2 answers

Best way to add the custom exception for the spring boot code

How to display the appropriate error message when some exception occurs. Suppose during GET methods if the data is not found, it should display the custom exception message. Similarly if we are trying to delete the data which is not…
AVINASH M
  • 487
  • 3
  • 7
  • 19
10
votes
3 answers

Python: Maximum recursion depth exceeded when printing custom exception

The following code throws RuntimeError: maximum recursion depth exceeded while getting the str of an object. I can resolve the infinite recursion in two different ways, but I don't understand why each fix works and thus don't know which to use, or…
andylytical
  • 113
  • 7
8
votes
10 answers

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

Why is it a "bad idea" to throw your own exceptions? found here
acheo
  • 3,106
  • 2
  • 32
  • 57
8
votes
2 answers

python calling custom exceptions from if-statement and try-except

So, I've created a custom exception that I want to call in 2 different ways (a if/else statement, and a try/except statement). Here is the custom exception: class CustomException(Exception): def __init__(self, value=None, *args, **kwargs): …
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
7
votes
3 answers

Uncatchable custom exception C++

This has been driving me crazy all night. class ExceptionImpl; /** * Custom Exception. */ class Exception : public virtual std::exception { public: Exception( const Exception& original ); Exception( const std::string& message ); …
Ben Crowhurst
  • 8,204
  • 6
  • 48
  • 78
7
votes
6 answers

what's the advantages to define custom exception?

Any big reasons to define custome exceptions in Java?
user496949
  • 83,087
  • 147
  • 309
  • 426
7
votes
2 answers

Best practice of log custom exceptions in PHP

I have a custom exception (which is further extended in may other custom exceptions). My project requires log all the customExceptions (and all of its decendents) that occurs. I have a logger that can log customException (and anything else). One of…
7
votes
4 answers

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…
Evan
  • 4,450
  • 10
  • 40
  • 58
7
votes
2 answers

Why is it not necessary to catch the IllegalArgumentException?

I wonder why the IllegalArgumentException class does not need to be catched or declared, while other exceptions have to (eg java.net.MalformedURLException). public void foo() { throw new IllegalArgumentException("spam"); } public void bar()…
Niklas R
  • 16,299
  • 28
  • 108
  • 203
7
votes
3 answers

Writing custom exceptions in C++

I am coming from a Ruby and Java background and have recently begun exploring C++. While my initial attempts at creating custom exceptions by simply subclassing exception class failed with obscure, I found the following example posted on a…
lorefnon
  • 12,875
  • 6
  • 61
  • 93
6
votes
1 answer

Exception class copy constructor

I'm testing how throwing when doing stack unwinding calls std::terminate by having the copy constructor of the class that is used to throw, throwing. Per C++14 N4296 - §15.1.3: Throwing an exception copy-initializes (8.5, 12.8) a temporary…
AdvSphere
  • 986
  • 7
  • 15
1
2
3
16 17