Skip to content

Title: [Bug] ApiException is not caught in v6 SDK even with try-catch block #2365

@JiataoYu

Description

@JiataoYu

Describe the bug

We recently upgraded from Microsoft Graph Java SDK v5 to v6. After migration, GraphServiceException was removed as expected, and the documentation suggests catching ApiException instead.

However, when we wrap calls like
try { Presence presence = graphClient.users().byUserId(id).presence().get(); } catch (ApiException e) { log.warn("Caught ApiException", e); // Never triggered } catch (Exception e) { log.warn("Caught generic exception", e); // Also not triggered }
in a try-catch block for ApiException, the exception is not caught. Even a catch block for Exception does not work. This leads to unhandled failures where the thread appears to terminate or hang, and the fallback logic is not triggered.

Q:

  • Do we need to manually register OData error models in v6?
  • Is this a known bug in ApiException mapping in recent Kiota-generated SDKs?

Expected behavior

try { User me = graphClient.me().get(); } catch (ApiException e) { // should reach here }

How to reproduce

The exception is thrown internally (e.g., shows in logs), but is never caught by the surrounding try-catch. Even when wrapping with Exception or Throwable, the block is skipped entirely.

SDK Version

implementation 'com.microsoft.graph:microsoft-graph:6.20.0'     implementation 'com.azure:azure-identity:1.15.4'     implementation 'com.microsoft.kiota:microsoft-kiota-bundle:1.7.0'

Latest version known to work for scenario above?

6.20

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

Java 17

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions