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
0 answers

Java not recognizing custom exception class and not compiling?

I have been working on a program to control an L.E.D. matrix with a RaspberryPi 3B+ and I wanted to structure my program so each Matrix would be an array of MatrixComponents. package matrixcontroller; public class MatrixComponent throws…
0
votes
0 answers

How to loosely couple user-defined exceptions?

I have a bunch of entities that I do CRUD on, ex. Car, Boat, Banana, etc. All of these have similar exceptions that I throw when something goes wrong. For example, if I'm trying to retrieve something but it doesn't exist I throw an…
GuitarStrum
  • 713
  • 8
  • 24
0
votes
2 answers

How can I call what() after throwing an unhandled, custom exception?

When you throw and unhandled std::runtime_error, the terminal automatically prints the result of what() making debugging a lot easier. Example: #include int main() { throw std::runtime_error("This is an error message.\n"); } Console…
Thynome
  • 71
  • 7
0
votes
1 answer

InvalidCharacterException not catching characters

I'm doing an assignment for a class that requires me to throw a RuntimeException if an invalid character is entered by the user. This input will be used to convert an expression that's in post fix-notation to infix. Now, I have my assignment…
0
votes
1 answer

C++ Indicate Class Function Throws Custom Exception

I've tried about 20 attempts & read numerous pages for the last 2 hours and can't figure out what I'm doing wrong here: #pragma once #include using namespace std; class EmptyHeap : public exception { public: virtual const char*…
Joseph Schmidt
  • 119
  • 1
  • 10
0
votes
3 answers

Illegal start of expression while throwing an exception?

I keep getting the error Illegal start of expression in this part of the code. switch(length) { case 1: if(message.equalsIgnoreCase("End")){ throws new AnotherException("Stop",true); } else { throws new…
0
votes
1 answer

Save method override and exceptions management

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…
Rui Gonçalves
  • 2,423
  • 6
  • 30
  • 42
0
votes
1 answer

Can I raise and handle exceptions in the same function

I am raising an exception and trying to handle the exception in snippet. The raising exception part and handling exception part are done in a function. Is it wrong to do so? import sys def water_level(lev): if(lev<10): raise…
Butters
  • 21
  • 7
0
votes
0 answers

Extending Angular ExceptionHandler, types not comparing

I have this simple class: export class MyError extends Error {} export class AnotherError extends Error {} export class CustomExceptionHandler implements ExceptionHandler { call(exception: any, stackTrace = null, reason = null) { if…
adam nowak
  • 785
  • 2
  • 9
  • 17
0
votes
5 answers

Does each custom exception in Java require its own class..?

I'm new to Java custom exceptions. I see many examples of how to create them, but there are two questions I cannot find answers to: 1) Can a custom exception be defined within the object class it's intended for, or must it be in its own class…
spinjector
  • 3,121
  • 3
  • 26
  • 56
0
votes
3 answers

Invalid Exception

So I programmed this exception for a lab I'm doing: public class InvalidDNAException extends Exception{ public InvalidDNAException(String message){ super(message); } } and then tried to put the exception into the class I'm using…
0
votes
1 answer

TypeError when calling custom exception

I'm trying to throw a custom error when incorrect input is used to create an object, but am getting this error when trying to raise the exception. TypeError: exceptions must derive from BaseException Here is the relevant code I'm working with def…
23k
  • 1,596
  • 3
  • 23
  • 52
0
votes
1 answer

Custom Errors in ASP.net MVC6

I have created an ASP.net 5 MVC6 project and added the following: app.UseStatusCodePages(); inside my Configure method. If I run the application, open my web browser and navigate to the following URL:…
Cool Breeze
  • 1,289
  • 11
  • 34
0
votes
2 answers

PHP Return from Function and Stop Processing

I have a simple function within a class. I'm trying to get increase exception handling by using try/catch. My problem is that the returning from the try/catch is not stopping processing in the function. Here's my code: class Config { public static…
Ken J
  • 4,312
  • 12
  • 50
  • 86
0
votes
0 answers

Rails 4 throw error if url is visited not using ask

I'm building a small API with rails and would like to protect the routes so that if someone attempts to access the api over http it will throw a JSON error response. Would this something I would setup in the controller or on a route level?
Sam Mason
  • 1,037
  • 1
  • 8
  • 29