custom-exceptions

Catching custom exception from WCF

匆匆过客 提交于 2019-12-25 06:47:19
问题 I have a Custom class, InvalidCodeException in Project A public class InvalidCodeException : Exception { public InvalidCodeException () { } public InvalidCodeException (string message) : base(message) { } public InvalidCodeException (string message, Exception innerException) : base(message, innerException) { } } a WCF service in Project B. And a client in Project C. Project A is referenced in Project B and C. I am throwing InvalidCodeException from Project B and catching in Project C. Problem

Unable to wrap DAO exception in service layer using Spring MVC

懵懂的女人 提交于 2019-12-24 11:22:03
问题 I am trying to handle custom exception handling using Spring MVC. DAO layer exception handler by service layer and service layer wrap that exception and handle that exception by Controller exception handler by Spring MVC. Following is my code: @Override public void saveNewMachineDetails(Machine machine, Configurations configurations) throws DataNotPersist{ logger.info("call service saveNewMachineDetails method"); try{ machineRepository.saveAndFlush(machine); }catch(Exception ex){ // logger

What arguments does the built-in Exception class require?

做~自己de王妃 提交于 2019-12-24 03:03:22
问题 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 BaseException , the docs state if you want to create a user defined exception, use Exception . What are the required arguments that should be passed to the Exception constructor without violating LSP ? class StudentValueError(Exception): """Base

ASP.NET MVC 2 Model Errors with Custom Exceptions

*爱你&永不变心* 提交于 2019-12-24 00:34:22
问题 I have a custom exception class: public class MyException: Exception { public MyException(MyExceptionEnum myError) : base(myError.ToDescription()) { } public MyException(MyExceptionEnum myError, Exception innerException) : base(myError.ToDescription(), innerException) { } } .ToDescription is a extension method on MyExceptionEnum to provide enum-to-string mapping for the exception error details. Here's how i throw it: if (someCondition) throw new MyException(MyExceptionEnum.SomeError); So i

Creating a custom exception class and custom handler class in Laravel 5.3

徘徊边缘 提交于 2019-12-23 18:34:20
问题 Before I get to the code, let me explain my aim. My web app displays vehicles for sale. I have a need for a custom 404 page that will display 12 of the latest vehicles added to the database if the user tries to access a page that doesn't exist. I have the following... App\Exceptions\CustomException.php <?php namespace App\Exceptions; use Exception; class CustomException extends Exception { public function __construct() { parent::__construct(); } } App\Exceptions\CustomHandler.php <?php

Custom Python Exceptions with Error Codes and Error Messages

此生再无相见时 提交于 2019-12-18 10:17:01
问题 class AppError(Exception): pass class MissingInputError(AppError): pass class ValidationError(AppError): pass ... def validate(self): """ Validate Input and save it """ params = self.__params if 'key' in params: self.__validateKey(escape(params['key'][0])) else: raise MissingInputError if 'svc' in params: self.__validateService(escape(params['svc'][0])) else: raise MissingInputError if 'dt' in params: self.__validateDate(escape(params['dt'][0])) else: raise MissingInputError def _

Custom Python Exceptions with Error Codes and Error Messages

China☆狼群 提交于 2019-12-18 10:16:03
问题 class AppError(Exception): pass class MissingInputError(AppError): pass class ValidationError(AppError): pass ... def validate(self): """ Validate Input and save it """ params = self.__params if 'key' in params: self.__validateKey(escape(params['key'][0])) else: raise MissingInputError if 'svc' in params: self.__validateService(escape(params['svc'][0])) else: raise MissingInputError if 'dt' in params: self.__validateDate(escape(params['dt'][0])) else: raise MissingInputError def _

Custom exceptions to Http status codes in ASP.NET API

拥有回忆 提交于 2019-12-12 11:41:18
问题 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 codes? 回答1: This is possible using Response.StatusCode setter and getter. Local Exception handling: For local action exception handling, put the following inside the calling code. var responseCode = Response.StatusCode; try { // Exception was

repeating OdbcException C#

霸气de小男生 提交于 2019-12-12 02:35:57
问题 I am using OdbcConnection class to connect to an external database. As a part of this process, I am also trying to handle the various exceptions thrown by this class (OdbcException). I find that the OdbcException contains a list called Errors which has multiple OdbcErrors. If I provide wrong credentials, I am able to get the access denied error but they are repeated twice in the errors list. The Errors list contains two errors but they are not unique. At the user end I see : ERROR [HY000]

Creating exceptions that are co-operative

独自空忆成欢 提交于 2019-12-11 06:05:24
问题 The Python docs state: Programs may name their own exceptions by creating a new exception class (see Classes for more about Python classes). Exceptions should typically be derivedfrom the Exception class, either directly or indirectly. ... When creating a module that can raise several distinct errors, a common practice is to create a base class for exceptions defined by that module, and subclass that to create specific exception classes for different error conditions. From Python’s super()