Skip to content

This is a tutorial project. JavaBasics_Task_176_V0.1 Demonstrating exception propagation using the throws keyword for document access simulation. 250226_1401

License

Notifications You must be signed in to change notification settings

YuriiJavaDev/JavaBasics_Task_176_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Secret Document Access (JavaBasics_Task_176_V0.1)

📖 Description

This project demonstrates the use of the throws keyword in Java to delegate exception handling. Instead of catching a FileNotFoundException locally, the method declares it in its signature, passing the responsibility of error management to the calling method.

📋 Requirements Compliance

  • Task: Create accessSecretDocument(String documentPath) method.
  • Mechanism: Use the throws FileNotFoundException declaration in the method signature.
  • Implementation: Attempt to instantiate a FileReader without a local try-catch block.
  • Goal: Delegate the potential "file not found" error to the caller.

🚀 Architectural Stack

  • Java 8+

🏗️ Implementation Details

The accessSecretDocument method illustrates how checked exceptions work in Java. Since FileNotFoundException is a checked exception, any method attempting to open a file must either handle the exception or declare it using throws. The calling method (main) implements a try-catch block to provide feedback if the specified file path is invalid.

📋 Expected result

Error: non_existent_file.txt (The system cannot find the file specified)

💻 Code Example

Project Structure:

src/com/yurii/pavlenko/
                └── Solution.java

Code

package com.yurii.pavlenko;

import java.io.FileNotFoundException;
import java.io.FileReader;

public class Solution {

    public static void main(String[] args) {
        try {
            accessSecretDocument("non_existent_file.txt");
        } catch (FileNotFoundException e) {
            System.out.println("Error: " + e.getMessage());
        }
    }

    public static void accessSecretDocument(String documentPath) throws FileNotFoundException {
        FileReader reader = new FileReader(documentPath);
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_176_V0.1 Demonstrating exception propagation using the throws keyword for document access simulation. 250226_1401

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages