The “correct” way to define an exception in Python without PyLint complaining

When you call super, you need the subclass/derived class as the first argument, not the main/base class. From the Python online documentation: class C(B): def method(self, arg): super(C, self).method(arg) So your exception would be defined as follows: class MyException(Exception): def __init__(self, message): super(MyException, self).__init__(message) self.message = message

Mock exception raised in function using Pytest

You can mock error raising via side_effect parameter: Alternatively side_effect can be an exception class or instance. In this case the exception will be raised when the mock is called. In your case, this can be used like this (assuming call_api is defined in module foo): import pytest from unittest.mock import patch def test_api(): with … Read more

Why new std::nothrow version is not widely used [duplicate]

However, I hardly see this version in my experience. You would use it (or, equivalently, catch the exception from the default version) if you can handle the failure locally; perhaps by requesting to free some other memory and then retrying, or by trying to allocate something smaller, or using an alternative algorithm that doesn’t need … Read more

Extending Throwable in Java

I’d say that it is a really bad idea. A lot of code is implemented on the assumption that if you catch Error and Exception you have caught all possible exceptions. And most tutorials and textbooks will tell you the same thing. By creating a direct subclass of Throwable you are potentially creating all sorts … Read more

Throwing an AggregateException in my own code

Are you talking about something like this? var exceptions = new List<Exception>(); foreach (var item in items) { try { DoSomething(item); } catch (Exception ex) { exceptions.Add(ex); } } if (exceptions.Count > 0) throw new AggregateException( “Encountered errors while trying to do something.”, exceptions ); Seems like the most logical way to me.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)