Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tutoria_Examples_T03
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mahboobe Shakeri
Tutoria_Examples_T03
Commits
2f7a7838
Commit
2f7a7838
authored
5 months ago
by
Mahboobe Shakeri
Browse files
Options
Downloads
Patches
Plain Diff
Exception examples added
parent
8c99ed01
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Main.java
+38
-0
38 additions, 0 deletions
src/Main.java
with
38 additions
and
0 deletions
src/Main.java
+
38
−
0
View file @
2f7a7838
...
...
@@ -8,6 +8,44 @@ import java.io.*;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
// Exception Examples
try
{
int
[]
grades
=
{
97
,
78
,
80
};
System
.
out
.
print
(
grades
[
5
]);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
try
{
int
[]
numbers
=
{
1
,
2
,
3
};
System
.
out
.
println
(
numbers
[
5
]);
// This will throw ArrayIndexOutOfBoundsException
}
catch
(
ArrayIndexOutOfBoundsException
e
)
{
System
.
out
.
println
(
"EECEPTION : "
+
e
.
getMessage
());
}
// String filename = "example.txt";
// String data = "This is an example of writing to and reading from a file.\n the second line";
//
// // Step 1: Create and write to the file
// try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
// writer.write(data);
// System.out.println("Data written to file: " + filename);
// } catch (IOException e) {
// System.out.println("Error writing to file: " + e.getMessage());
// }
//
// // Step 2: Close the file (automatically closed with try-with-resources)
//
// // Step 3: Reopen and read from the file
// try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
// String line;
// System.out.println("Reading from file: " + filename);
// while ((line = reader.readLine()) != null) {
// System.out.println(line);
// }
// } catch (IOException e) {
// System.out.println("Error reading from file: " + e.getMessage());
// }
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment