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

What arguments does the built-in Exception class require?

As a followup to my previous question, I was trying to create co-operative user defined exceptions that don't violate LSP. I tried to search the PEPs and use PyCharm but I was unable to get a clear answer. I only found this PEP, but it talks about…
user11217210
2
votes
3 answers

How to raise my exceptions instead of built-in exceptions?

In some cases, I need to raise my exception because built-in exceptions are not fit to my programs. After I defined my exception, python raises both my exception and built-in exception, how to handle this situation? I want to only print mine? class…
Bahram Aghaei
  • 40
  • 1
  • 6
2
votes
0 answers

Parameterized exception type

In Scala I can generate an exception that carries a value of some type parameter A via case class MyException[A]( value: A ) extends Exception Is there a way to define a similar type in F#? exception MyException<'a> of 'a is not possible as far as I…
Matthias Schlaipfer
  • 510
  • 1
  • 3
  • 15
2
votes
3 answers

How to create a custom exception which wraps mutliple exceptions in java

How to create a custom exception which wraps three different exceptions like InvalidContextException, IllegalArgumentException. For example, let's say there is a method: public void method() throws IOException, IllegalArgumentException,…
James Kristen
  • 75
  • 1
  • 3
  • 12
2
votes
1 answer

C# Can a custom exception catch/kill itself?

My code looks like this var i = 0; try { i = faultyProcedure(); } catch (Exception ex) { try { throw new CustomException("faultyProcedure called", ex); } catch (CustomException) {} } Though it works, it looks silly. The…
Guenther
  • 403
  • 2
  • 16
2
votes
0 answers

On different errors set different view files in Zend Framework

I have dispatch error listener and there I get thrown exception and check if it is instance of CustomeException. In that case I want to set custom view template with default layout. public function attach(EventManagerInterface $events, $priority =…
2
votes
1 answer

No Output for password checker with custom exception Java

I am trying to make a program that checks a password from user input. The password criteria are that it has at least 10 characters, where at least 1 is a digit, 1 is a lower case and one is an upper case letter. For the assignment I have to create a…
2
votes
3 answers

When it is best not to create user-defined exceptions?

I have made a component that throws Exception. I'm thinking if I should stick with standard throw new Exception or if I should create specific exceptions. I also consider user-defined exception as not appealing when it throws exception from Remoting…
Hao
  • 8,047
  • 18
  • 63
  • 92
2
votes
1 answer

Java custom exception not working properly

I'm creating a little Timer program that has 3 input fields (hours, minutes and seconds). For some reason, the OverTwentyFourException exception doesn't work for the hours input field. Here's parts of my code: static JTextField userInputHrs; static…
Daniel
  • 452
  • 6
  • 14
2
votes
2 answers

Should I use a relevant built-in unchecked exception where the theory prescribes using a checked one?

There are quite a few posts on SO about the "checked vs unchecked exception" topic. This answer is probably the most well-rounded and informative. Yet I'm still conflicted to follow the logic presented there, and there's a reason for that. I'm…
Semisonic
  • 1,152
  • 8
  • 21
2
votes
1 answer

ASP.NET MVC 2 Model Errors with Custom Exceptions

I have a custom exception class: public class MyException: Exception { public MyException(MyExceptionEnum myError) : base(myError.ToDescription()) { } public MyException(MyExceptionEnum myError, Exception innerException) :…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
2
votes
1 answer

Using custom Exceptions

I was wondering how I would use a custom made exception with another class. For example I am making a Card class and an invalidCardException. How can I use the methods from the Card class inside of the exception class and vice versa? Here's an…
Tyler
  • 39
  • 6
2
votes
1 answer

Boost example code inheriting from std::exception doesn't link

This article from boost: Error and Exception Handling puts forth the following program code: #include struct my_exc1 : std::exception { char const* what() const throw(); }; struct my_exc2 : std::exception { char const* what() const…
Timtro
  • 418
  • 5
  • 15
2
votes
1 answer

Exception filter not triggered

I wanted to add the ExceptionFilter to my project at work. So i made a test api project with VS2013 on .net 4.5: A web api get action throws a custom exception (Has a filter attribute) Custom exception constructor being build Filter exception catch…
YanivHer
  • 123
  • 14
2
votes
1 answer

Get model of Laravel exceptions

I'm trying to make custom exceptions messages with Laravel 4.2. I use a function firstorfail() in a route to load a profile page, and I've made an error handler, following the doc (link) App::error(function(ModelNotFoundException $e) { …
Corentin
  • 149
  • 9