Snippets tagged “exceptions”
14 snippets use this tag.
- Can I catch multiple Java exceptions in the same catch clause?Java
Yes, you can catch multiple exceptions in the same catch clause in Java.
- Catch multiple exceptions in one line (except block)Python
In Python, you can catch multiple exceptions in a single except block by separating the exceptions with a tuple.
- Creating an instance using the class name and calling constructorJava
To create an instance of a class using its class name and calling its constructor, you can use the Class.forName method and the newInstance method.
- How can I write a `try`/`except` block that catches all exceptions?Python
You can catch all exceptions by using the Exception class in the except block, like this:
- How do I check whether a file exists without exceptions?Python
Three approaches to find a file
- How to Get JavaScript Stack Trace When Throwing an ExceptionJavaScript
Read this JavaScript tutorial and learn useful information about the two methods that are used in programming to get stack trace when throwing an exception.
- How to get the position of a character in Python?Python
You can use the index() method to get the position of a specific character in a string.
- How to properly ignore exceptionsPython
It's generally not recommended to ignore exceptions, as they often indicate a problem in the code that should be addressed.
- Is there a goto statement in Java?Java
No, Java does not have a goto statement.
- Manually raising (throwing) an exception in PythonPython
In Python, you can raise an exception using the raise statement.
- Proper way to declare custom exceptions in modern Python?Python
To declare a custom exception in Python, you can create a new class that inherits from the built-in Exception class.
- Spring Boot - How to log all requests and responses with exceptions in single place?Java
In a Spring Boot application, you can log all requests and responses, along with exceptions, in a single place by using a combination of Spring Boot's logging framework and request/response interceptors.
- Try/Catch block in PHP not catching ExceptionPHP
There could be several reasons why a try/catch block in PHP is not catching an exception.
- What could cause java.lang.reflect.InvocationTargetException?Java
The java.lang.reflect.InvocationTargetException is a checked exception that is thrown when an exception is thrown by an invoked method or constructor.