Can you sense javac errors using Powershell?

Viewed 12

I am using javac in Powershell right now, but I am having an issue. The message

selected file has been succesfully compiled:)

I made it show after compilation shows up even if there have been errors during compilation. Here is my current code:

function Compile {
javac (-join ($File, ".java"))
Write-Host $File -NoNewline -ForegroundColor Cyan
" has been succesfully compiled:)"}

I tried using the trap statement like this:

function Compile {
trap{
[System.Media.SystemSounds]::Exclamation.Play()
return}
javac (-join ($File, ".java"))
Write-Host $File -NoNewline -ForegroundColor Cyan
" has been succesfully compiled:)"}

and I also tried using try and catch

function Compile {
try {
javac (-join ($File, ".java"))}
catch{
[System.Media.SystemSounds]::Exclamation.Play()
return}
Write-Host $File -NoNewline -ForegroundColor Cyan
" has been succesfully compiled:)"}

but neither of those two actually worked. I need to find a way to sense javac errors. Is there a way to actually do that?

0 Answers
Related