custom-exceptions

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

末鹿安然 提交于 2019-12-11 03:49:02
问题 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 building a wrapper API around a set of services similar to each other. There are, however, minor differences between them (or a possibility of such in the future), so that certain functions (of secondary and shortcut nature) may be supported by some

Custom Exception C#

不问归期 提交于 2019-12-10 21:04:16
问题 I would like to create my own custom Exception (for my own practice), I have Man class and i would like to check the name (so its not empty, null and only English chars. I'm not sure if I'm doing this right, 1.do i need to write the code that handles with the error (if occures) in the Custom Exception class? or in the Man's setter? 2. Where should i use the "throw new Exception" for best practice? 3. any comments\improvements about my code would be welcome. using System; using System

How to know when to use an existing Exception or write a custom Exception?

帅比萌擦擦* 提交于 2019-12-10 15:50:34
问题 Thanks for the input on this question, I've decided to go with making my Create() method throw exceptions so as Jon Skeet said, you don't have to handle them everywhere and can just let them bubble up, seems the best approach for larger applications. So now I create instances of my classes with this code: try { SmartForms smartForms = SmartForms.Create("ball"); smartForms.Show(); } catch (CannotInstantiateException ex) { Console.WriteLine("Item could not be instantiated: {0}", ex.Message); }

Pros and Cons of implementing a generic custom exception

帅比萌擦擦* 提交于 2019-12-10 15:25:24
问题 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")] TestError, ... } } Create a custom exception class: public class CustomException : ApplicationException { protected Enums.Errors _customError; public CustomException(Enums.Errors customError) { this._customError = customError; } public override string Message { get {

Python - Implementing Custom exceptions

隐身守侯 提交于 2019-12-10 12:15:37
问题 I have a project that I need to run and have no idea how to implement custom exceptions. It mostly does complicated scientific functions, to be vague. Mostly it will be raising exceptions if something is not set. I've been given this as a starting example from runnables. # Define a class inherit from an exception type class CustomError(Exception): def __init__(self, arg): # Set some exception infomation self.msg = arg try: # Raise an exception with argument raise CustomError('This is a

Display custom message when constraint is violated PL/SQL

徘徊边缘 提交于 2019-12-10 12:12:24
问题 I'm writing a pl/sql procedure. I've got a constraint on a column which doesn't allow values below 0 and above 500. I need to display a custom message if this constraint is violated (eg. "ID out of range"). Currently this is the exception and also the output in getting. There is another procedure that is outputting the error, hence the use raise_applcation_error. Exception when VALUE_ERROR then raise_application_error(-20002, 'Customer ID out of range'); Error Message "ORA-20000: ORA-02290:

What type of exception to throw in this case?

南楼画角 提交于 2019-12-07 01:19:46
问题 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 of course I could try opening the application, or telling the user to open it, or ...). Should I implement a custom exception - or use the existing NotSupportedException (or one of the other .NET exceptions). If a custom exception, what would you

Handing multiple exception of same type and resume execution in python

流过昼夜 提交于 2019-12-05 14:49:47
It appears that one cannot resume the execution of test once you hit the raise the user defined exception in Python. But in my scenario I want to check error occurred for different input values. But Current implementation is restricting to continue the check error for the different input vectors. However, before coming up with some sort of convoluted solution to my problem, I figured I would ask the experts and see if there is something I'm missing. Unfortunately, I cannot change this paradigm easily without significant re-factoring . My application looks similar to this: Input will be given

Using mockito to test methods which throw uncaught custom exceptions

爱⌒轻易说出口 提交于 2019-12-05 08:46:33
问题 How do I write a Mockito-based JUnit method to test this method adduser() ? I tried writing one, but it's failing with an error message saying exception is not handled. The error is displayed for: when(service.addUser("nginx")).thenReturn("apache"); Assume addUser() method in business class never catches any exception and rethrowing is not done. class Business { public User addUser() throws ServiceException{ User user = service.addUser("nginx"); return user; } } TEST CASE METHOD : Here in the

What type of exception to throw in this case?

风流意气都作罢 提交于 2019-12-05 06:16:39
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 of course I could try opening the application, or telling the user to open it, or ...). Should I implement a custom exception - or use the existing NotSupportedException (or one of the other .NET exceptions). If a custom exception, what would you suggest? I was thinking of implementing a custom exception I'd call it MyAppNameException and then just