question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use generated exceptions

See original GitHub issue

So I’m trying to use SSM and catch scenario where value doesn’t exist. The call generates botocore.errorfactory.ParameterNotFound: An error occurred (ParameterNotFound) when calling the GetParameter operation

The thing is that ParameterNotFound does not exist the class with the error is dynamically generated and I can’t reference it in the code (or at least not from botocore.errorfactory.ParameterNotFound). What’s the point of having exceptions like this when they can’t be caught? Why bothering with dynamically generated class, when you could just have a generic error and inside of its properties I could extract the actual cause. Or is there a way to use it that I’m not aware of?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
takedacommented, Aug 28, 2019

Yes, this is what I ended up doing, my point is that those dynamically generated classes for exceptions are pointless. You don’t have a static class that you can use to catch them, thankfully they all inherit from ClientError so one can catch them the way you showed the problem is that when you see botocore.errorfactory.ParameterNotFound it’s not obvious how to handle it. You don’t know that it inherits from ClientError and you don’t know that exception name could be the error code. I would like to propose abolish the dynamic classes and simply raise ClientError so it shows ClientError('ParameterNotFound', ...) or similar that makes it clear what exception happened and how to catch it.

2reactions
swetashrecommented, Aug 30, 2019

@takeda - Modeled exceptions can be accessed through the client. Instead of botocore.errorfactory.ParameterNotFound you can do client.exceptions.ParameterNotFound.

client = boto3.client('ssm')

try:
   response = client.get_parameter(Name='sweta')
except client.exceptions.ParameterNotFound as e:
    print(e)

I agree that this is confusing and the current documentation is insufficient. More information on this can be found at this pr: boto/botocore#1113 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Chapter 4] 4.3 Generating Exceptions
4.3 Generating Exceptions ... A Java program can use the exception-handling mechanism to deal with program-specific errors in a clean manner. A program...
Read more >
Handling XML GENERATE exceptions - IBM
To handle errors, use either or both of the following phrases of the XML GENERATE statement: ON EXCEPTION; COUNT IN. If you code...
Read more >
Compiler-generated exceptions | Microsoft Learn
Learn about compiler-generated exceptions. Review a list of automatically thrown exceptions and their error conditions.
Read more >
How to Throw Exceptions in Java - Rollbar
Throwing an exception is as simple as using the "throw" statement. You then specify the Exception object you wish to throw. Every Exception...
Read more >
8. Errors and Exceptions — Python 3.11.1 documentation
When an exception is created in order to be raised, it is usually initialized with information that describes the error that has occurred....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found