visit_url() not aborting on blank page

bumcheekcity

Active member
What's the best way of making:

Code:
string a = visit_url("some_page.php?condition=1");

NOT abort if it hits a blank page. I'm actually trying to check for if a page is blank, and i thought assigning it to a variable would work, but no dice.
 

slyz

Developer
If the scripts decides to abort during the try part, won't it exit anyway after the finally part is done? I haven't played around with those yet, and I can't test right now.
 

Winterbay

Active member
I guess you could have a variable that is set after the potential abort and check for that in the finally part. If it has been set then there were no problem in the try-part. But this is untested, I have not even tried to make a try-finally statement yet, at all :)
 

Theraze

Active member
If the scripts decides to abort during the try part, won't it exit anyway after the finally part is done? I haven't played around with those yet, and I can't test right now.

Believe that abort will only abort the try, not the whole script... not certain of that, but if not, it sort of kills part of the reasoning for having an abort-capture system...
 

slyz

Developer
I tested with this script:
PHP:
print( "Start testing." );
try
{
	abort( "Aborting now" );
}
finally
{
	print( "Let's see if the rest of the script will execute now." );
}
print( "You can continue, the abort has been trapped!" );
This resulted in:
Code:
> call test.ash

Start testing.
[COLOR="#ff0000"]Aborting now[/COLOR]
Let's see if the rest of the script will execute now.

The try...finally structure wasn't added to capture aborts, only to allow you to execute some more instructions in case of an abort.

However, doing this worked:
PHP:
void abort_trap()
{
	try
	{
		abort( "Aborting now" );
	}
	finally
	{
		print( "Let's see if the rest of the script will execute now." );
		return;
	}
	return;
}

void main()
{
	print( "Start testing." );
	abort_trap();
	print( "You can continue, the abort has been trapped!" );
}

Code:
> call test.ash

Start testing.
[COLOR="#ff0000"]Aborting now[/COLOR]
Let's see if the rest of the script will execute now.
You can continue, the abort has been trapped!

I guess you could place your visit_url() calls into a special abort trapping function, like this:
PHP:
string safe_visit_url( string url )
{
	string response;
	try
	{
		response = visit_url( url );
	}
	finally
	{
		return response;
	}
	return response;
}
I can't find any url that will give me a blank page right now, so I can't test this, but it should work I guess.

EDIT: I tried with "canadia.php" (I'm muscle sign). It works!
PHP:
string safe_visit_url( string url )
{
	string response;
	try
	{
		response = visit_url( url );
	}
	finally
	{
		return response;
	}
	return response;
}

void main()
{
	print( "Start testing." );
	//string res = visit_url( "canadia.php" );
	string res = safe_visit_url( "canadia.php" );
	print( "You can continue, the abort has been trapped!" );
}
With a simple visit_url():
Code:
> call test.ash

Start testing.
[COLOR="#ff0000"]Server www2.kingdomofloathing.com returned a blank page from canadia.php. Complain to Jick, not us.[/COLOR]
With safe_visit_url():
Code:
> call test.ash

Start testing.
[COLOR="#ff0000"]Server www2.kingdomofloathing.com returned a blank page from canadia.php. Complain to Jick, not us.[/COLOR]
You can continue, the abort has been trapped!
 
Last edited:

Winterbay

Active member
Cool. Using that I can finally get BCCs script to not abort on the Chasm as soon as I'm not a muscle sign...
 

Bale

Minion
A bug? You think that try finally should work differently? This is quite useful.

Or do you mean aborting on a blank response from visit_url() is a bug? I think there are good reasons for that also.
 
Top