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

Using exception filtering in c# 6.0 (with typeof()) VS. catching custom exception

I have a method for manage exception handling as below. The Question is that, in case that the typeof exception is our point, which approach is recommended? Using catch (System.Exception ex) when(ex.GetType() ==typeof(ExcOneException)){...} or catch…
Elnaz
  • 2,854
  • 3
  • 29
  • 41
4
votes
5 answers

Custom Exception C#

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…
Coder123
  • 784
  • 2
  • 8
  • 29
4
votes
1 answer

Custom exceptions to Http status codes in ASP.NET API

I have a couple of custom exceptions in my business layer that bubble up to my API methods in my ASP.NET application. Currently, they all translate to Http status 500. How do I map these custom exceptions so that I could return different Http status…
Sam
  • 26,817
  • 58
  • 206
  • 383
4
votes
2 answers

Passing arguments into a custom exception

I've learned recently how to create custom exceptions in Python and implement them into a class. I'm trying to add an additional argument into my exception for more clarity, and can't seem to get the formatting done correctly. Here's what I'm…
23k
  • 1,596
  • 3
  • 23
  • 52
4
votes
2 answers

Handing multiple exception of same type and resume execution in python

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…
user5143593
4
votes
2 answers

Inheriting built-in exceptions classes besides System.Exception

Is it good practice to inherit system exceptions besides Exception, if it makes sense? For example, would it be sensible to inherit System.InvalidOperationException, if my custom exception is specific kind of 'invalid operation'? The reason I'm…
Dan Stevens
  • 6,392
  • 10
  • 49
  • 68
4
votes
4 answers

Custom RunTime Exceptions

So this is regarding an interview question I was recently asked. The interviewer started on this by asking me how we create our custom Exceptions. On answering that, he asked me how I'd create a RunTimeExceptions. I said we'd create them in the same…
Chan
  • 651
  • 2
  • 8
  • 15
4
votes
2 answers

Customizing exceptions in python? writing logs in custom exception class?

I am customizing exceptions in my python code. I have inherited exception class in to other and now defining some custom errors as classes derived from my custom exception class like this: class DataCollectorError(Exception): pass class…
Inderpal Singh
  • 270
  • 2
  • 8
  • 24
4
votes
2 answers

Convert JSR303 JavaBean Validation exceptions to custom exceptions

I have implemented the JSR303 JavaBean Validation in the Service layer of my web app (according to this article). Now I want to convert all validation exceptions (e.g. javax.validation.ConstraintViolationException) to my custom exception. I created…
citress
  • 889
  • 3
  • 13
  • 35
3
votes
2 answers

Catching all crashes in C# .NET

There are already some pretty good threads on this topic on Stack Overflow, but there doesn't really seem to be a concise answer on any of them. My C# console application (running as a Windows service) launches a Java process and manages it…
user470760
3
votes
2 answers

Are python-ldap's exceptions organized in a hierarchy?

I have a code like this: try: .... l.simple_bind_s(user, password) except ldap.CONNECT_ERROR, e: sys.exit(1) except ldap.BUSY, e: sys.exit(2) except ldap.OPT_NETWORK_TIMEOUT, e: sys.exit(3) except ldap.TIMEOUT, e: …
kursat
  • 1,059
  • 5
  • 15
  • 32
3
votes
0 answers

Can I construct a java.lang.StackTraceElement that references a non-Java-file?

I'm writing a library that parses text files that are not written in Java. When I encounter a syntax error in these text files, I would like to construct a clickable stack trace with the relevant file name and line number of these files. I already…
Johannes Brodwall
  • 7,673
  • 5
  • 34
  • 28
3
votes
1 answer

How to manage errors with bokeh library (Python + JavaScript) and show them on the user interface?

I am working in a Bokeh Server Application using the Python library "Bokeh" and I usually get two types of errors. JavaScript errors on the Chromium console Python errors on the server side, they appear in the Tornado logger. Bokeh works with the…
ChesuCR
  • 9,352
  • 5
  • 51
  • 114
3
votes
2 answers

Return information with Custom Exceptions C#

I have the following problem: I have a service method: public bool EmployeeCanReiceivePayment(int employeeId) { ... int workingHours = this.GetEmployeeWorkingHours(employeeId); if(workingHours < N) { throw new…
StefanL19
  • 1,476
  • 2
  • 14
  • 29
3
votes
6 answers

.net exceptions

When should I create my own custom exception class rather than using a one provided by .Net? Which base exception class should I derive from and why?
Moon
  • 33,439
  • 20
  • 81
  • 132