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
0
votes
1 answer

Is it good practice to throw custom exception from catch statement?

I have command line tool which runs tests. There is test runner class, which does some preparation before test execution and then runs the test and makes a report. Is it OK if my classes catch an exception and throw new custom exception to the upper…
Elephant
  • 675
  • 1
  • 8
  • 18
0
votes
0 answers

__getattr__ on Exception subclass

So I'm (of course) writing a library that interacts with an API, and the API can sometimes return errors. I came up with a context manager to catch dynamic errors, but I'd like to do something a little quicker: class APIError(Exception): def…
AbyxDev
  • 1,363
  • 16
  • 30
0
votes
0 answers

How to write a custom exception for Input stream that may end prematurely

I would like to write a custom exception (RunTimeException) for Input stream that may end prematurely instead of catching IOException for the following code: public static int deserializeInt(InputStream inputStream) { int deserializeObject; …
Salem Masoud
  • 411
  • 11
  • 32
0
votes
1 answer

How to access StackTrace property form my Custom Exceptions in dot net core

I'm trying to implement my own custom exceptions in dot net core. This is what I have so far: public class WSException: Exception { // some custom stuff... private readonly string _developerMessage = ""; public string DeveloperMessage {…
opensas
  • 60,462
  • 79
  • 252
  • 386
0
votes
1 answer

Why doesn't rails 2.1 catch exceptions with rescue_from?

in my ApplicationController, I have rescue_from StorageExceptions::AuthorizationFailed, :with => handle_auth_error def handle_auth_error redirect_to error_path(403) end but the code is not catching this error. I have checked that what is being…
cmouse
  • 672
  • 1
  • 6
  • 22
0
votes
3 answers

Custom exception class for java

I need to write a custom exception class for a Java program. For example, when trying to remove an existing product from a list, an exception should be thrown with a statement saying "error". I tried using this, but I don't know if it's…
suba
  • 33
  • 7
0
votes
1 answer

Symfony2 - Getting 'Attempted to load class "Exception" from namespace "AppBundle\Controller".'

Throwing simple exceptions are a common practice, so I would think it would be 'built-into' Symfony2, 'right out of the box". However, executing the following code, I get the error partly shown in this question's title and fully shown below. if(…
user2505564
0
votes
2 answers

java array fixed element for constructor

I'm writing my firsts classes in java. I did a class with an int[] that must be declared with 3 elements. public abstract class MyClass { private String name; private int[] myValues = new int[2]; now my question is: what is the best way to…
Marco
  • 133
  • 2
  • 13
0
votes
0 answers

PHP Exception Standards

Say, for example, I have a MailQueue class with a function queue, which takes a from address, a subject, a body, and an array of recipients. The function validates the given parameters for presence and email address validity, and then attempts to…
Mike Pearson
  • 79
  • 1
  • 5
0
votes
1 answer

Radix Sort- Calling Expected exceptions

I am working on a program that uses Radix Sort that reads in words from a file and sorts in ascending order. In order to do this, we must check that all the words in the file are the same length and there is nothing in the file but letter (no…
K. Wonder
  • 21
  • 4
0
votes
1 answer

Apache camel: Adding parameters to throwException statement

I have a custom exception class, customException, which when called is needing three parameters (two integers and String). Currently in my camel.xml file I have:
shirafuno
  • 387
  • 3
  • 9
  • 24
0
votes
0 answers

Custom exceptions in Elasticsearch Nest

In the documentation it’s possible to define custom exceptions via ConnectionConfiguration as said here: var settings = new ConnectionConfiguration() .SetConnectionStatusHandler(r=> { if (r.HttpStatusCode == 403) throw new…
Michał J. Gąsior
  • 1,457
  • 3
  • 21
  • 39
0
votes
3 answers

How to handle Exceptions in Rest API whit Spring boot

I need to handle the exceptions in My rest API. I have a layered architecture, composed by Entities, DAOs, Services and controllers. In my services I have the model Exceptions, and I need to know the best way to translate these exceptions to send…
0
votes
0 answers

Program crashes when throwing/catching custom exceptions

I have a problem while throwing/catching custom exceptions. Context: I am making a property (as in real estate) manager that stores properties, tenants, bank accounts, and transactions as classes, and combines them under a contract. Each transaction…
Dimos
  • 33
  • 10
0
votes
1 answer

Throwing a custom error in a module meant to be imported by arbitrary modules (library)

I'm building a python library that implements a task queue. If for whatever reason the thread that processes the tasks dies, and the option to restart the thread isn't set, I need to throw an exception. Is this something that I should just throw a…
Falmarri
  • 47,727
  • 41
  • 151
  • 191