Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/functions/templates/recipes/common/error-handling.md
1# Error Handling Patterns23> **MANDATORY**: All function implementations MUST include proper error handling with logging.45## Python67```python8import logging910try:11# Your function logic here12result = process_data(data)13logging.info(f"Success: processed {item_id}")14except Exception as error:15logging.error(f"Error processing {item_id}: {error}")16raise # Re-raise to trigger retry/dead-letter17```1819## TypeScript2021```typescript22try {23// Your function logic here24const result = await processData(data);25context.log(`Success: processed ${itemId}`);26} catch (error) {27context.error(`Error processing ${itemId}:`, error);28throw error; // Re-raise to trigger retry/dead-letter29}30```3132## JavaScript3334```javascript35try {36// Your function logic here37const result = await processData(data);38context.log(`Success: processed ${itemId}`);39} catch (error) {40context.error(`Error processing ${itemId}:`, error);41throw error; // Re-raise to trigger retry/dead-letter42}43```4445## C# (.NET)4647```csharp48try49{50// Your function logic here51var result = await ProcessDataAsync(data);52_logger.LogInformation($"Success: processed {itemId}");53}54catch (Exception ex)55{56_logger.LogError(ex, $"Error processing {itemId}");57throw; // Re-raise to trigger retry/dead-letter58}59```6061## Java6263```java64try {65// Your function logic here66Result result = processData(data);67context.getLogger().info("Success: processed " + itemId);68} catch (Exception e) {69context.getLogger().severe("Error processing " + itemId + ": " + e.getMessage());70throw e; // Re-raise to trigger retry/dead-letter71}72```7374## PowerShell7576```powershell77try {78# Your function logic here79$result = Process-Data -Data $data80Write-Host "Success: processed $itemId"81}82catch {83Write-Error "Error processing $itemId : $_"84throw # Re-raise to trigger retry/dead-letter85}86```8788## Key Principles89901. **Always log before throwing** - Enables debugging from logs912. **Re-throw exceptions** - Allows Functions runtime to handle retry/dead-letter923. **Include context in logs** - Item ID, operation name, relevant metadata934. **Use appropriate log levels** - Info for success, Error for failures94